On 30/01/2016 00:31, timm wrote:
> specifically, to add 100,000,000 nums, gawk took 10.9 secs and python took 11 .0 secs (or 17.8 secs depending on the python code)
> ===========================
> # add 100,000,000 nums in gawk
> $ cat count.awk
> # add 100,000,000 nums in gawk
> BEGIN {for(i=1;i<10^8;i++) j+=i; print j}
>
> $ time gawk -f count.awk
> 49999995000000
> ===========================
> $ cat count1.py
> # add 100,000,000 nums in python
> j = 0
> for i in xrange(10**8):
> j += i
> print j
>
> $ time python count1.py
> 49999995000000
That's odd; those results seem to be for sums to 10 million-1 not 100
million-1.
Also Python starts from 0 not 1, but that's not significant. Python is
faster if the code is put inside a function (something to do with local
name lookups being faster).
(On my machine, not a fast one, that Python code ran in 31 seconds to
give 4999999950000000. Inside a function, it took 19 seconds. With PyPy,
about 8 or 9 seconds.
Your Awk code took 21 seconds on a GAWK.EXE 3.1.6 from 2008.)
--
Bartc