No such thing as a small change | |
PerlMonks |
Re: Unpacking and convertingby BrowserUk (Patriarch) |
on Feb 15, 2011 at 22:18 UTC ( [id://888398]=note: print w/replies, xml ) | Need Help?? |
Your code above never does anything with the modified $item--ie. it never pushes it into @newdata, which means that your loop does exactly nothing, but slowly. However, looking past that... This is weird but shifting items one by one into new array seems to be a lot faster than iterating over the array with canonical for (@list). Update: Ignore. The Benchmark is broken! Frankly, I thought you were talking through the top of your hat when you said that, until I benchmarked it. And, despite my spending a while trying to see a flaw in the benchmark, you seem to be right. Not only am I surprised that it seems to be true, but I'm utterly staggered by the difference in performance. And at an utter loss to explain why it should be the case.
And the bigger the array, the more extraordinary the difference becomes:
There is something amiss here, but if it is the benchhmark I cannot see it. And if not, I'm loathed to explain why creating a new array by pushing them one at a time whilst destroying the old one, would be so much faster than iterating over the original in place. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In Section
Seekers of Perl Wisdom
|
|