Microbenchmark: Summing over array of doubles
beliavsky at aol.com
beliavsky at aol.com
Mon Aug 2 10:33:38 EDT 2004
bulatov at engr.orst.edu (Yaroslav Bulatov) wrote in message news:<4d642979.0407312049.7a8aecab at posting.google.com>...
> I made an array of 10 million floats timed how long it takes to sum
> the elements, here's what I got (millis):
>
> gcc -O2: 21
> Python with numarray: 104
> Python with Numeric: 302
> java: 325
> gcc: 348
> Python with Psyco: 1317
> Pure Python using sum: 2312
> Pure Python: 5631
>
> http://yaroslav.hopto.org/russianwiki/index.php/c-numeric-speed
>
> numarray takes over Numeric at about 1100 floats
>
> I'm doing intensive computation on arrays in Python, so if you have
> suggestions on Python/C solutions that could push the envelope, please
> let me know.
What hardware are you using?
On a 2.8 GHz Intel Pentium 4, a Fortran 95 code compiled with Compaq
Visual Fortran 6.6C using the -optimize:5 option takes 40
milliseconds. Probably you could improve the speed of the C program by
compiling it with the Intel C compiler. The Fortran program speed is
constrained by array accesses, not the additions (which are done in
hardware). A program to compute sum(xx**4) takes the same time as one
to compute sum(xx).
program xsum_double
! sum 1e7 doubles
implicit none
integer, parameter :: n = 10000000
real(kind=8) :: xx(n)
real :: t1,t2,xsum
call random_seed()
call random_number(xx)
call cpu_time(t1)
xsum = sum(xx)
call cpu_time(t2)
print*,1000*(t2-t1),xsum
end program xsum_double
More information about the Python-list
mailing list