Skip to content

Instantly share code, notes, and snippets.

@mephinet
Last active November 15, 2017 08:02
Show Gist options
  • Save mephinet/a890016edf13938b93237766bfe83d38 to your computer and use it in GitHub Desktop.
Save mephinet/a890016edf13938b93237766bfe83d38 to your computer and use it in GitHub Desktop.
perl autoload performance
#! /usr/bin/env perl
use strict;
use warnings;
use v5.10;
package A;
use Moose;
use namespace::autoclean;
sub foo {
my $self = shift;
}
package B;
use Moose;
use namespace::autoclean;
use vars qw($AUTOLOAD);
sub AUTOLOAD {
return if ( $AUTOLOAD =~ /DESTROY/ );
my $self = shift;
}
__PACKAGE__->meta->make_immutable;
package main;
use Time::HiRes qw(gettimeofday tv_interval);
my $executions = 100000;
my $ts = [gettimeofday];
for ( 1 .. $executions ) {
my $a = A->new();
$a->foo();
}
say tv_interval($ts);
$ts = [gettimeofday];
for ( 1 .. $executions ) {
my $b = B->new();
$b->foo();
}
say tv_interval($ts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment