6 use Benchmark qw[timethese];
10 This benchmark is designed to measure how long things with type constraints
11 take (constructors, accessors). It was created to measure the impact of
12 inlining type constraints.
43 isa => 'ArrayRef[Int]',
48 isa => 'ArrayRef[Str]',
53 isa => 'ArrayRef[FileHandle]',
58 isa => 'ArrayRef[Object]',
63 isa => 'HashRef[Int]',
68 isa => 'HashRef[Str]',
73 isa => 'HashRef[FileHandle]',
78 isa => 'HashRef[Object]',
81 __PACKAGE__->meta->make_immutable;
85 my @strs = 'a' .. 'j';
86 my @fhs = map { my $fh; open $fh, '<', $0 or die; $fh; } 1 .. 10;
87 my @objects = map { Thing->new } 1 .. 10;
89 my %ints = map { $_ => $_ } @ints;
90 my %strs = map { $_ => $_ } @ints;
91 my %fhs = map { $_ => $_ } @fhs;
92 my %objects = map { $_ => $_ } @objects;
101 object => $objects[0],
105 a_object => \@objects,
109 h_object => \%objects,
113 my $thing = Thing->new;
115 $thing->int( $ints[0] );
116 $thing->str( $strs[0] );
117 $thing->fh( $fhs[0] );
118 $thing->object( $objects[0] );
119 $thing->a_int( \@ints );
120 $thing->a_str( \@strs );
121 $thing->a_fh( \@fhs );
122 $thing->a_object( \@objects );
123 $thing->h_int( \%ints );
124 $thing->h_str( \%strs );
125 $thing->h_fh( \%fhs );
126 $thing->h_object( \%objects );