File: references.pl

package info (click to toggle)
libclass-prototyped-perl 1.11-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 544 kB
  • sloc: perl: 1,448; makefile: 8
file content (42 lines) | stat: -rwxr-xr-x 761 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use Benchmark qw(cmpthese timeit);

package My::Funky::Class;

sub foo {
	print "hi\n";
}

package main;

$My::Funky::Class::mirrors = { $package => 'foo' };

mytimethese(500_000, {
	stringref => sub {
		my %foo = %{"$package\::"};
	},
	'bless_variable' => sub {
		bless {}, $package;
	},
	'bless_constant' => sub {
		bless {}, 'My::Funky::Class';
	},
});



sub get_package {
	my $string = shift;

	my $pkg = \%main::;	foreach (split(/::/, $string)) {$pkg = $pkg->{"$_\::"};}
	return $pkg;
}

sub mytimethese {
	my($iter, $codehash) = @_;

	foreach my $desc (sort keys %$codehash) {
		print "$desc:" . ' 'x(50-length($desc));
		my $time = timeit($iter, $codehash->{$desc});
		print sprintf('%8.2f usec', ($time->[1]+$time->[2])*1_000_000/$time->[5])."\n";
	}
}