speed of python vs matlab.
Chao
devincyu at gmail.com
Wed Dec 13 20:27:28 EST 2006
My Bad, the time used by python is 0.46~0.49 sec,
I tried xrange, but it doesn't make things better.
import time
tic = time.time()
a = 1.0
array = range(1000)
for i in array:
for j in array:
a = a + 0.1
toc = time.time()
print toc-tic,' has elapsed'
used by matlab is 0.012sec
tic
a = 1;
for i=1:1000
for j=1:1000
a = a + 1;
end
end
toc
used by ruby is 0.94~0.96sec
a = 1
start = Time.now()
1000.times do
1000.times do
a = a + 1
end
end
finish = Time.now()
puts finish - start
Andrew Sackville-West wrote:
> On Wed, Dec 13, 2006 at 04:07:20PM -0800, Chao wrote:
> > I've been trying to develop some numerical codes with python, however
> > got disappointed.
> >
> > A very simple test,
> >
> > a = 1.0
> >
> > for i in range(1000):
> > for j in range(1000):
> > a = a+1
> >
> > unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
> > 3.0G, 1G RAM, it varies according to machine configuration, but should
> > be in the same level)
>
> somethings not right there.
>
> andrew at debian:~$ cat pytimetest.py
> a=1.0
> for i in range (1000):
> for j in range (1000):
> a=a+1
>
>
> andrew at debian:~$ time python pytimetest.py
>
> real 0m0.534s
> user 0m0.528s
> sys 0m0.000s
>
>
> andrew at debian:~$ cat /proc/cpuinfo | grep name
> model name : Intel(R) Celeron(R) CPU 2.53GHz
>
> andrew at debian:~$ uname -a
> Linux debian 2.6.18-3-686 #1 SMP Mon Dec 4 16:41:14 UTC 2006 i686
> GNU/Linux
>
> A
>
> --7AUc2qLy4jB3hD7Z
> Content-Type: application/pgp-signature
> Content-Disposition: inline;
> filename="signature.asc"
> Content-Description: Digital signature
> X-Google-AttachSize: 190
More information about the Python-list
mailing list