Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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

by haukex (Prior)
on May 19, 2017 at 12:43 UTC ( #1190607=note: print w/replies, xml ) Need Help??

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

Your second solution is actually what I tried first but it is also slower than my current solution.

How exactly did you measure this - code, sample input, etc.? Because at least under the following conditions, my code suggestion appears to be faster than yours. (Note I inserted use warnings; use strict; at the top of my script.)

$ perl -wMstrict -le 'print join(" ",map {int(rand(100))-50} 0..rand(7 +)+3) for 1..1000000' >in.txt $ wc -l in.txt 1000000 in.txt $ head -5 in.txt -49 43 0 -35 0 -20 -49 5 46 -11 -14 39 39 -24 -49 36 -7 -36 -43 15 30 5 -4 11 37 -25 27 -49 21 49 33 -15 -16 17 10 32 -14 -30 $ time perl in.txt >out.txt real 0m1.869s user 0m1.863s sys 0m0.004s $ time perl in.txt >out.txt real 0m1.539s user 0m1.521s sys 0m0.016s

Replies are listed 'Best First'.
Re^4: printing every 2nd entry in a list backwards
by Anonymous Monk on May 19, 2017 at 13:06 UTC

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

      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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1190607]
[GrandFather]: It's either lines that your browser won't split (no white space) or nodes with <pre> tags which ought to be code tags
[GrandFather]: I haven't noticed the problem for a while, but it can be hard to find the nasty node. If you do find it, consider it and with luck a janitor will fix it

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2017-05-24 00:56 GMT
Find Nodes?
    Voting Booth?