Feeds:
Posts
Comments

Posts Tagged ‘benchmark’

Sue D. Nymme comments on my blog:

I think Moose is fantastic, awesome, intuitive, helpful – except for one thing: its awful, unforgivable speed penalty. When writing GUI or CGI programs, I simply cannot wait eight to twelve seconds for a program to start. Ergo, none of my local library modules use Moose.

8 – 12 seconds for a program to start!? I don’t remember it being that quite bad when I used it.

moose.pl

use Moose;

1;

nomoose.pl :-)

1;

test.pl

use Benchmark qw(:hireswallclock);

use strict;
use warnings;

my $perl = 'c:/strawberry/perl/bin/perl';

Benchmark::timethese(100, {
    'moose'   => sub { system(qq{$perl moose.pl}) },
    'nomoose' => sub { system(qq{$perl nomoose.pl}) },
});
c:\home\jared> perl test.pl
Benchmark: timing 100 iterations of moose, nomoose...
     moose: 33.6734 wallclock secs ( 0.00 usr +  0.14 sys =  0.14 CPU) @ 709.22/s (n=100)
            (warning: too few iterations for a reliable count)
   nomoose: 1.25888 wallclock secs ( 0.06 usr +  0.17 sys =  0.23 CPU) @ 427.35/s (n=100)
            (warning: too few iterations for a reliable count)

Yikes, it’s more than 25 times slower! But is it really that bad? It’s adding between 0.3 and 0.35 seconds to the start time. That actually sounds quite reasonable. And when you consider that a typical large perl program will load a whole bunch of other modules which also add to the start time, maybe it will start to get lost in the noise.

Based on this test, rejecting Moose solely on start-up time overhead seems a little unreasonable. (There could be some more overhead if you actually try to use it mind you.)

test2.pl

Just in case I’d used Benchmark incorrectly, I tried something a bit more "traditional" (read hacky).

use strict;
use warnings;

my $script = shift;
my $perl = 'c:/strawberry/perl/bin/perl';

for (1..100) {
    system("$perl $script");
}
$ time perl test2.pl nomoose.pl

real    0m5.784s
user    0m0.015s
sys     0m0.000s

$ time perl test2.pl moose.pl

real    0m38.146s
user    0m0.000s
sys     0m0.046s

Read Full Post »

Follow

Get every new post delivered to your Inbox.