This will come as a surprise to few, but performing a separate
system calls (e.g: for
`factor "$n"` in Perl or
in C), on each iteration of a loop can really kill performance. One option
to reduce that would be to read individual lines from a
seq 2 999999 | xargs factor loop, or avoid forking altogether.
I discovered this issue while working on Project Euler problem #141, and I should have realised that the sub-100% CPU utilisation of the program was caused by the excessive spawning of new processes.