Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by Anonymous Monk
on May 19, 2017 at 12:25 UTC ( #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 (Prior) 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
Node Status?
node history
Node Type: note [id://1190603]
help
Chatterbox?
[marto]: better: "If a type of behaviour, event, or situation is par for the course, it is not good but it is normal or as you would expect"
[Discipulus]: thanks i was unable to decide where to split the sentece
[marto]: FWIW search.cpan rarely has issues, see http://noc.perl. org for a route to report problems
[oakbox]: thanks, marto.
[marto]: there was a period where search.cpan had some frequent outages for (IIRC) a couple of weeks. I've not had any problems since, until today.
[marto]: this was about 16 months ago maybe. the noc team are, in my experience, very responsive to reports of issues, so please raise the issue after checking known problems/outages

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-07-26 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (389 votes). Check out past polls.