210
|
1 #!/usr/bin/perl
|
|
2 use strict;
|
412
|
3 use Carp;
|
|
4 use Time::HiRes qw(gettimeofday tv_interval);
|
|
5 use Scalar::Util qw(blessed);
|
|
6 my $slot;
|
|
7 my $ref = bless \$slot, 'Wrapper';
|
|
8 sub is {
|
|
9 my $slot = shift;
|
|
10 bless \$slot, 'Wrapper';
|
|
11 }
|
395
|
12
|
412
|
13 sub instanceOf {
|
|
14 carp "A typename can't be undefined" unless $_[1];
|
|
15 blessed($_[0]) and $_[0]->isa($_[1])
|
|
16 }
|
|
17
|
|
18 my $bar = Bar->new();
|
|
19
|
|
20 my $t = [gettimeofday];
|
407
|
21
|
412
|
22 for(my $i =0; $i< 1000000; $i++) {
|
|
23 is($bar)->instanceOf('Bar');
|
|
24 }
|
|
25
|
|
26 print "Is: ",tv_interval($t,[gettimeofday]),"\n";
|
|
27
|
|
28 $t = [gettimeofday];
|
|
29
|
|
30 for(my $i =0; $i< 1000000; $i++) {
|
|
31 instanceOf($bar, 'Bar');
|
|
32 }
|
|
33
|
|
34 print "Is: ",tv_interval($t,[gettimeofday]),"\n";
|
407
|
35
|
|
36
|
412
|
37 package Wrapper;
|
|
38 use Scalar::Util qw(blessed);
|
|
39 sub instanceOf {
|
|
40 blessed(${$_[0]}) and ${$_[0]}->isa($_[1]);
|
|
41 }
|
|
42
|
|
43 package Bar;
|
|
44 use IMPL::declare {
|
|
45 base => ['IMPL::Object' => undef]
|
|
46 };
|
|
47
|
407
|
48 1;
|