for (0..1_000_000) {
$x=$_+1;
}
Or in C or Java:
int i, x;
for(i = 0; i < 1000000; i++) {
x = i + 1;
}
C and Java optimizers can turn the above into this:
int x = 1000000;
Thus totally eliminating the loop. Run your C compiler with -O0, and you'll get comparible performance to the Perl version.
Why isn't this test relevent? Because the C/Java optimizer cannot always unroll loops. This is fairly common in any real-world program.
---- Reinvent a rounder wheel.
Note: All code is untested, unless otherwise stated
|