Perl code 37 times quickly than Python code??
Bruce Ramsay
bramsay-ns at attbi.com
Tue Jan 15 22:37:55 EST 2002
Toni,
The results are slightly different if you fix a bug in the Perl
script. See below. This is a good argument for using Python instead
of some other languages.
1000Mhz Athlon:
bruce at wheat:~$ time python xa.py
real 0m1.150s
user 0m1.150s
sys 0m0.000s
bruce at wheat:~$ time perl xa.pl
real 0m1.364s
user 0m1.360s
sys 0m0.000s
That's 16% faster for Python.
Bruce Ramsay
gaya at infomail.lacaixa.es (Toni Gaya) wrote in message news:<61f6bfa8.0201151153.1cd018ae at posting.google.com>...
> > python
> > ------
> > def Ramp(result, size, start, end):
> > step = (end-start)/(size-1)
> > for i in xrange(size):
> > result[i] = start + step*i
> >
> > def main():
> > array = [0]*10000
> > for i in xrange(100):
> > Ramp(array, 10000, 0.0, 1.0)
> >
> > main()
>
> perl
> ----
> sub Ramp {
> local (*result, $size, $start, $end) = @_;
my $i;
> $step = ($end-$start)/($size-1);
> for ($i=0; $i<$size; $i++)
> {
> $result[$i] = $start + $step*$i;
> }
> }
>
> sub main {
> for ($i = 0 ; $i < 10000 ; $i++) {
> push(@array, 0);
> }
> for ($i=0; $i<100; $i++) {
> do Ramp(*array, 10000, 0.0, 1.0);
> }
> }
>
> do main();
>
>
> Results in a PII 233 Mhz:
> [root at localhost source]# time python array.py
> 5.18user 0.00system 0:05.19elapsed 99%CPU (0avgtext+0avgdata
> 0maxresident)k
> 0inputs+0outputs (253major+153minor)pagefaults 0swaps
>
> [root at localhost source]# time perl array.pl
> 0.14user 0.00system 0:00.14elapsed 98%CPU (0avgtext+0avgdata
> 0maxresident)k
> 0inputs+0outputs (261major+186minor)pagefaults 0swaps
>
> I suppose two programs generate same result, is not?. I like Python,
> but Python program execution is 37 times long that Perl program. What
> is WRONG??
More information about the Python-list
mailing list