Last active
November 15, 2017 08:02
-
-
Save mephinet/a890016edf13938b93237766bfe83d38 to your computer and use it in GitHub Desktop.
perl autoload performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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