http://qs321.pair.com?node_id=216886


in reply to Dreaming in Perl

To answer your question, the first and third will probably be about the same speed. The second will be significantly slower (lots of memory), and the fourth will be obscenly complicated. If it's much slower or about the same (or even faster!) depends mostly on how (explicitly) parallel your brain is.

theorbtwo can't sleep either, but wasn't dreaming of code... as far as he remembers.


Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Replies are listed 'Best First'.
Re^2: Dreaming in Perl
by Aristotle (Chancellor) on Dec 02, 2002 at 23:41 UTC

    I'm too lazy to benchmark, but since I know for(;;) is implemented in terms of while(){} continue{} and am fairly certain the list for the foreach is generated lazily in Perl5 (and thus juggling memory is not an issue), I'll hazard a guess that #3 should be the be the fastest of the lot.

    FWIW, I don't remember ever dreaming of code. Then again, I rarely ever remember anything but the worst of anxiety ridden dreams, so I may well have. Who knows?

    Makeshifts last the longest.