On Thu, 30 Nov 2006 19:36:17 -0800, David Harvey
<[EMAIL PROTECTED]> wrote:
> On Nov 30, 2006, at 10:34 PM, William Stein wrote:
>>> It's really incredible that MAGMA goes faster than python ints here.
>>> From memory, at sage days 2, our Integer stuff was still a factor of
>>> 7-10 away from python ints, at least for addition.
>>
>> I don't know what benchmark you were doing exactly, but now that
>> the dust
>> has
>> settled here's what you actually accomplished for addition, which
>> is better
>> than a factor of 7-10: http://modular.math.washington.edu:8101/
>> benches2
>>
>> {{{
>> def b_python(a,b):
>> a=int(a)
>> b=int(b)
>> t=cputime()
>> for i in range(int(10^6)):
>> c = a+b
>> return cputime(t)
>> }}}
>
> You need to try this last one again in pyrex, using a cdef int i for
> the loop counter, and doing the arithmetic with python ints; and then
> compare that to the same thing using SAGE Integers.
OK, I've done that. But honestly, I don't know what it is really timing,
since the optimizing compiler could be doing all kinds of interesting
things with unrolling loops, macros, etc. And it's really pretty unfair,
since the point is optimizing an interpreter rather than a compiler.
With that benchmark though, object creation is basically 12 times faster
for Python ints, though again I think one has to be careful in intepreting
how these things mean, when we're really trying to benchmark an interpreter
and the object-creation-overhead of that interpreter.
== benches2 ==
{{{
%sagex
import sage.all
def b_python2(a,b):
cdef int i
a=int(a)
b=int(b)
t=sage.all.cputime()
for i from 0 <= i < 1000000:
c = a+b
return sage.all.cputime(t)
}}}
{{{
def b_python(a,b):
a=int(a)
b=int(b)
t=cputime()
for i in range(int(10^6)):
c = a+b
return cputime(t)
}}}
{{{
%sagex
import sage.all
def b_sage2(a,b):
cdef int i
a=sage.all.Integer(a)
b=sage.all.Integer(b)
t=sage.all.cputime()
for i from 0 <= i < 1000000:
c = a+b
return sage.all.cputime(t)
}}}
{{{
def b_sage(a,b):
a=Integer(a)
b=Integer(b)
t=cputime()
for i in range(int(10^6)):
c = a+b
return cputime(t)
}}}
{{{
def b(a,b):
t_python = b_python(a,b)
t_python2 = b_python2(a,b)
t_sage = b_sage(a,b)
t_sage2 = b_sage2(a,b)
print len(str(a)), len(str(b)), t_python,t_sage, t_sage/t_python,
t_python2, t_sage2, t_sage2/t_python2
}}}
{{{
b(3,4)
///
1 1 0.28 0.92 3.28571428571 0.02 0.5 25.0
}}}
{{{
b(939834,290283)
///
6 6 0.27 0.91 3.37037037037 0.04 0.51 12.75
}}}
{{{
b(9023809823409823,239048230948023848)
///
16 18 0.27 0.92 3.40740740741 0.03 0.52 17.3333333333
}}}
{{{
b(2903402834098234892034802,293048203948029384092834082340892)
///
25 33 0.34 0.87 2.55882352941 0.1 0.55 5.5
}}}
{{{
b(29023042903840923840928340982390482038,29038490283409238498230482390482038420)
///
38 38 0.35 0.86 2.45714285714 0.1 0.51 5.1
}}}
{{{
b(19^1000,1793^3939)
///
1279 12816 6.87 2.2 0.320232896652 6.66 1.81 0.271771771772
}}}
{{{
}}}
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---