Perl code 37 times quickly than Python code??
Toni Gaya
gaya at infomail.lacaixa.es
Tue Jan 15 14:53:49 EST 2002
> 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) = @_;
$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