Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by Anonymous Monk
on May 19, 2017 at 12:25 UTC ( [id://1190603]=note: print w/replies, xml ) Need Help??


in reply to Re: printing every 2nd entry in a list backwards (updated)
in thread printing every 2nd entry in a list backwards

Thank you kindly for your reply.

Your first solution is indeed exuding the knowledge of a monk, sadly it is rather slow.

Your second solution is actually what I tried first but it is also slower than my current solution. I am explicitly looking for a fast solution to beat the solution written in the language that also starts with "P" and must not be named.

I apologize for not being clear in the first place.

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

Replies are listed 'Best First'.
Re^3: printing every 2nd entry in a list backwards
by haukex (Archbishop) on May 19, 2017 at 12:43 UTC
    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 1190600.pl in.txt >out.txt real 0m1.869s user 0m1.863s sys 0m0.004s $ time perl 1190602.pl in.txt >out.txt real 0m1.539s user 0m1.521s sys 0m0.016s

      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 list.py in.txt >pyout.txt real 0m1.964s user 0m1.934s sys 0m0.028s $ time perl 1190602.pl in.txt >out2.txt real 0m1.953s user 0m1.921s sys 0m0.028s

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1190603]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-20 02:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found