Keep It Simple, Stupid | |
PerlMonks |
No Benchmark is better than a bad Benchmarkby Abigail-II (Bishop) |
on Aug 19, 2002 at 11:49 UTC ( [id://191143]=note: print w/replies, xml ) | Need Help?? |
You should always be very suspicious if your benchmark shows results
of 8823529.41 runs/second. Specially when it comes to non-trivial tasks
like sprintf() - after all, than requires perl to parse a format.
Another thing that should ring loud bells is that you are doing sprintf() in void context. That's not a natural operation. Perhaps Perl optimizes that away for you - totally screwing up your benchmark. It's a simple test: Indeed, you just benchmarked how fast perl can do an empty loop. Not very useful. Your benchmark should include assigning the result to a variable. So, you might want to do: It looks like sprintf is still a winner. But is it? Let's check the deparser again: Oops. Perl is so smart, it figured out at compile time the result of the sprintf. We'd have to make the arguments of sprintf variable to make Perl actually do work at run time: And only now we can run a fair benchmark: And guess what? unpack is the winner! The moral: no benchmark is better than a bad benchmark. Abigail
In Section
Seekers of Perl Wisdom
|
|