in reply to Overloading ref() just like ->isa and ->can?
What are you hoping to get out of ref() and what is it giving you now when you feed it your faker-objects?
Incidentally, if Scalar::Util's blessed() is available, $result = blessed($maybe_obj) and $maybe_obj->isa( ... ); might be faster than eval { $result->isa( ... ) };.
Rate eval2 blessed1 eval1 blessed2 eval2 6.80/s -- -57% -61% -76% blessed1 15.9/s 134% -- -9% -43% eval1 17.4/s 156% 10% -- -38% blessed2 28.0/s 313% 76% 61% --
Here's the test script:
#!/usr/bin/perl use strict; use warnings; use Scalar::Util qw( blessed ); use Benchmark qw( cmpthese ); my $obj = bless {}, 'Foo'; my $not_obj; my $result; cmpthese( -1, { eval1 => sub { for ( 0 .. 10_000 ) { $result = eval { $obj->isa('Foo') }; $result = eval { $obj->isa('Bar') }; } }, blessed1 => sub { for ( 0 .. 10_000 ) { $result = blessed($obj) and $obj->isa('Foo'); $result = blessed($obj) and $obj->isa('Bar'); } }, eval2 => sub { for ( 0 .. 10_000 ) { $result = eval { $not_obj->isa('Foo') }; $result = eval { $not_obj->isa('Bar') }; } }, blessed2 => sub { for ( 0 .. 10_000 ) { $result = blessed($not_obj) and $not_obj->isa('Foo'); $result = blessed($not_obj) and $not_obj->isa('Bar'); } }, });
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Overloading ref() just like ->isa and ->can?
by diotalevi (Canon) on Apr 18, 2006 at 17:27 UTC |