Do you know where your variables are? | |
PerlMonks |
Re^5: Can you improve upon my algorithm.by salva (Canon) |
on Mar 13, 2015 at 10:06 UTC ( [id://1119924]=note: print w/replies, xml ) | Need Help?? |
Oh, well, I meant if you do it in C, Perl has too much overhead for that.
For instance, removing everything not in the hot path for your script:
Perl compiles it into 40 OPs, 35 inside the loop: My estimation is that every OP performs between 50 and 100 machine instructions with a good proportion of performance-unfriendly conditional branches. So, roughly, every run of the loop above would require at least 2000 instructions and may be reaching the capacity of the L1 code cache. On the other hand, an N-way merge in C, on the hot path of the inner loop, requires just to perform a couple of operations plus the key comparisons log2N times. That may sum up to 50 instructions for every loop cycle (=sorted record)! update: Oops, I forgot to say, in theory! 1 hour to sort 100GB, actually, seems too fast to me. But I think the analysis is sound, and unless I am overlooking some hidden bottleneck, the order or magnitude should be right!
In Section
Seekers of Perl Wisdom
|
|