comparison _test/temp.pl @ 414:ec6f2d389d1e ref20150831

working on IMPL::Config::Bag
author cin
date Fri, 02 Oct 2015 06:56:24 +0300
parents 30e8c6a74937
children 3d24b10dd0d5
comparison
equal deleted inserted replaced
413:af8d359ee4cc 414:ec6f2d389d1e
1 #!/usr/bin/perl 1 #!/usr/bin/perl
2 use strict; 2 use strict;
3 use Carp; 3 use Carp;
4 use Time::HiRes qw(gettimeofday tv_interval); 4 use Time::HiRes qw(gettimeofday tv_interval);
5 use Scalar::Util qw(blessed); 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 }
12 6
13 sub instanceOf { 7 my $data = [1,2,3];
14 carp "A typename can't be undefined" unless $_[1];
15 blessed($_[0]) and $_[0]->isa($_[1])
16 }
17 8
18 my $bar = Bar->new(); 9 print foreach @$data, 4;
19
20 my $t = [gettimeofday];
21
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";
35
36
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 10
48 1; 11 1;