ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 03 Apr 2011 20:51:44 +0200gap calls seem to consume a lot of timehttps://ask.sagemath.org/question/8046/gap-calls-seem-to-consume-a-lot-of-time/
I am trying to migrate some code from GAP to sage, and the overhead for calls to GAP procedures is enormous. Here is an example:
----------------------------------------------------------------------
| Sage Version 4.6.2, Release Date: 2011-02-25 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: def test1():
....: for x in xrange(100): gap.eval('G:=Group([(1,2,3)])')
....:
sage: def test2():
....: gap.eval('for x in [1..100] do G:=Group([(1,2,3)]);od')
....:
sage: timeit('test1()')
5 loops, best of 3: 810 ms per loop
sage: timeit('test2()')
25 loops, best of 3: 12.6 ms per loop
Is there anything I am doing wrong?
I tried some profiling, which indicated that most of the time is consumed by "select.select".
Any help will be most welcome.Sat, 02 Apr 2011 13:30:45 +0200https://ask.sagemath.org/question/8046/gap-calls-seem-to-consume-a-lot-of-time/Answer by DSM for <p>I am trying to migrate some code from GAP to sage, and the overhead for calls to GAP procedures is enormous. Here is an example:</p>
<pre><code>----------------------------------------------------------------------
| Sage Version 4.6.2, Release Date: 2011-02-25 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: def test1():
....: for x in xrange(100): gap.eval('G:=Group([(1,2,3)])')
....:
sage: def test2():
....: gap.eval('for x in [1..100] do G:=Group([(1,2,3)]);od')
....:
sage: timeit('test1()')
5 loops, best of 3: 810 ms per loop
sage: timeit('test2()')
25 loops, best of 3: 12.6 ms per loop
</code></pre>
<p>Is there anything I am doing wrong?</p>
<p>I tried some profiling, which indicated that most of the time is consumed by "select.select".</p>
<p>Any help will be most welcome.</p>
https://ask.sagemath.org/question/8046/gap-calls-seem-to-consume-a-lot-of-time/?answer=12249#post-id-12249Yep, the gap interface is pretty slow, due to the I/O approach (hence the time in select.select). Fortunately for lots of use cases this isn't the bottleneck, but in some cases it can be, more's the pity. Work on a faster Cythonic interface is progressing -- see http://trac.sagemath.org/sage_trac/ticket/6391 -- but it's not quite there yet.
Instead of calling a gap function explicitly to build a permutation group, it's more idiomatic Sage to write
G = PermutationGroup([(1,2,3)])
which can be a little faster (~2x, maybe). Underlying problem is still there, though.Sat, 02 Apr 2011 14:24:39 +0200https://ask.sagemath.org/question/8046/gap-calls-seem-to-consume-a-lot-of-time/?answer=12249#post-id-12249Comment by parzan for <p>Yep, the gap interface is pretty slow, due to the I/O approach (hence the time in select.select). Fortunately for lots of use cases this isn't the bottleneck, but in some cases it can be, more's the pity. Work on a faster Cythonic interface is progressing -- see <a href="http://trac.sagemath.org/sage_trac/ticket/6391">http://trac.sagemath.org/sage_trac/ti...</a> -- but it's not quite there yet.</p>
<p>Instead of calling a gap function explicitly to build a permutation group, it's more idiomatic Sage to write</p>
<pre><code>G = PermutationGroup([(1,2,3)])
</code></pre>
<p>which can be a little faster (~2x, maybe). Underlying problem is still there, though.</p>
https://ask.sagemath.org/question/8046/gap-calls-seem-to-consume-a-lot-of-time/?comment=21926#post-id-21926Thanks for replying! Actually, the code I gave was just for example. The functions I'm interested in are within a GAP package called FGA (free group algorithms), and I don't think there is any parallel in sage (but I'll be glad to be corrected). In any case, the libGAP link gives me something to wait for!Sat, 02 Apr 2011 18:49:54 +0200https://ask.sagemath.org/question/8046/gap-calls-seem-to-consume-a-lot-of-time/?comment=21926#post-id-21926Comment by Volker for <p>Yep, the gap interface is pretty slow, due to the I/O approach (hence the time in select.select). Fortunately for lots of use cases this isn't the bottleneck, but in some cases it can be, more's the pity. Work on a faster Cythonic interface is progressing -- see <a href="http://trac.sagemath.org/sage_trac/ticket/6391">http://trac.sagemath.org/sage_trac/ti...</a> -- but it's not quite there yet.</p>
<p>Instead of calling a gap function explicitly to build a permutation group, it's more idiomatic Sage to write</p>
<pre><code>G = PermutationGroup([(1,2,3)])
</code></pre>
<p>which can be a little faster (~2x, maybe). Underlying problem is still there, though.</p>
https://ask.sagemath.org/question/8046/gap-calls-seem-to-consume-a-lot-of-time/?comment=21910#post-id-21910libGAP is feature-complete. You are more than welcome to test the current version and help review it.Sun, 03 Apr 2011 20:51:44 +0200https://ask.sagemath.org/question/8046/gap-calls-seem-to-consume-a-lot-of-time/?comment=21910#post-id-21910