in reply to Re^3: printing every 2nd entry in a list backwards
in thread printing every 2nd entry in a list backwards

Apologies for not mentioning how I measure performance, please refer to my other reply for more information

  • Comment on Re^4: printing every 2nd entry in a list backwards

Replies are listed 'Best First'.
Re^5: printing every 2nd entry in a list backwards
by haukex (Abbot) on May 19, 2017 at 13:13 UTC

    From this node:

    by creating a file with 1_000_000 entries, each line having 10 numbers and then running the script against it

    I still can't reproduce your evidence.

    $ perl -wMstrict -le 'print join(" ",map {int(rand(100))-50} 1..10) fo +r 1..1000000' >in.txt $ time python in.txt >pyout.txt real 0m1.964s user 0m1.934s sys 0m0.028s $ time perl in.txt >out2.txt real 0m1.953s user 0m1.921s sys 0m0.028s

      I just tried it on my laptop:

      $ python --version Python 2.7.12 $ time python in.txt > pyout.txt real 0m1.927s user 0m1.898s sys 0m0.028s
      $ perl -v This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-li +nux-thread-multi [...] $ time perl in.txt > haukex-out.t +xt real 0m2.309s user 0m2.290s sys 0m0.020s

      No differences in the two output files. However, note Perl 5.24.1 is faster than both Python 2.7.12 and Perl 5.18.1:

      $ perl5.24.1 -v This is perl 5, version 24, subversion 1 (v5.24.1) built for x86_64-li +nux-thread-multi [...] $ time perl5.24.1 in.txt > haukex +-out-5.24.1.txt real 0m1.759s user 0m1.740s sys 0m0.016s

      And also Python 3.4 is slower than any of the above:

      $ python3.4 --version Python 3.4.5 $ time python3.4 in.txt > pyout-3.4.txt real 0m2.493s user 0m2.444s sys 0m0.048s

        Good point! In my test above I was pitting Python 2.7.6 against Perl 5.22.0. I can confirm that both Perl 5.18.2. and Python 3.4.3 are slower by a factor of roughly 1.3 to 1.4 on my machine (those are just the versions I have lying around at the moment).