Perl users, especially beginners, are often surprised at how well Perl optimizes things, and that they don't have to code in round-about ways (as is the case in many other interpreted/scripting languages) to speed up their programs. And, from time to time, people are surprised that an operation which is seemingly efficient is actually dog-slow under Perl (eg. returning multiple elements per map call).
I have, of late, been running many general-interest benchmarks on this and that, and have actually come to the point where I'm naming my benchmark scripts, organizing them by keywords, and providing little blurbs as to what I learned from each benchmark. For example:
The point I'm trying to make is not regarding this particular benchmark (although it is edifying to know that method invocation doesn't have very much overhead), but regarding the usefulness of such information for the Perl community as a whole. I have noticed that a substantial portion of SoPW nodes relate to the issue of performance and have some sort of benchmarking in them, often of general interest.# keywords: method sub call overhead # learned: OO-style method invocation is only about 13% slower than d +irect invocation (v5.6) package Foo; use strict; use warnings; use Benchmark qw(cmpthese); sub new { bless {}, shift; } sub meth { my ($self, $val) = @_; $val; } my $obj = new Foo; my @params = (42, 1, 2, { a=> 'silly hashref'}, 'a string'); cmpthese (-3, { method => sub { $obj->meth(@params); }, direct => sub { meth($obj, @params); } });
So, I've been contemplating the idea of a "Benchmark Arena", where people could submit categorized benchmarks, and discuss specific performance-related issues. A Benchmark Arena could serve as a communinal repository of information regarding optimal ways of doing such-and-such under Perl, like a Q&A section, but devoted specifically to the issue of code performance. Because Perl offers so-many-WTDI, it is very enlightening to see several WTDI in action, and see how they compare against each other. The benchmark arena would ideally be keyword-searchable, so for example, the benchmark above could be found under the "method", "sub", "call", and "overhead" keywords, while benchmarks regarding map performance would be found by searching for "map", etc. Keyword categorization would allow much greater specificity of search results than would be possible with a plain-text search.
I believe something like this would serve as a very valuable resource to the Perl community at large, and would be ideal for Perlmonks. What have my fellow monks to say about this idea?