| 1 |
#!perl |
| 2 |
|
| 3 |
package foo; |
| 4 |
use common::sense; |
| 5 |
|
| 6 |
use base qw/Object::Event/; |
| 7 |
|
| 8 |
sub new { |
| 9 |
my $this = shift; |
| 10 |
my $class = ref($this) || $this; |
| 11 |
$class->SUPER::new (@_); |
| 12 |
} |
| 13 |
|
| 14 |
our $cnt; |
| 15 |
sub test : event_cb { $cnt++ } |
| 16 |
|
| 17 |
package main; |
| 18 |
use common::sense; |
| 19 |
|
| 20 |
use Benchmark qw/:all/; |
| 21 |
|
| 22 |
my $f = foo->new; |
| 23 |
|
| 24 |
for (1..10) { |
| 25 |
$f->reg_cb (test => sub { |
| 26 |
my ($f) = @_; |
| 27 |
$foo::cnt++; |
| 28 |
}); |
| 29 |
} |
| 30 |
|
| 31 |
my $ev; |
| 32 |
|
| 33 |
timethese (250000, { |
| 34 |
simple => sub { $f->event ('test') }, |
| 35 |
method => sub { $f->test } |
| 36 |
}); |
| 37 |
|
| 38 |
print "$foo::cnt\n"; |