The second suggested code posted performed best for my given hardward config, but always try speed tests on the correct hardware as OS's etc can effect performance.
So does the current load on the machine... which is one reason why a "benchmark" such as the one you supplied is essentially useless. Not one of the methods you tested ran for longer than 6 hundredths of a second. That's simply not adequate. You will need a much larger dataset before you'll get any performance data that is even remotely meaningful.
Many around here are happy to give advice to those obsessed with the performance of their code. That advice will almost certainly include statements like: "consider how long it takes to write as well as how long it takes to run" and "if you were really interested in performance you probably wouldn't be using perl in the first place." The upshot is that micro-optimizations simply aren't worth it. You are usually better off saving your time (or the maintainers) by writing clean, straight-forward code that is easy to read. Often enough, that approach leads to efficient code as well. When you really need better performance, you'll know it.
Afterall, consider that the code in question probably won't spend more time running in the next 5 years than you've already spent benchmarking it...
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Re: Arrays manipulation
by sauoq
in thread Arrays manipulation
by hotshot
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |