Re: [CDBI] Make name_lc go fast. Benchmarks
Michael G Schwern <[email protected]> Tue, 10 Apr 2007 08:02:38 -0400
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
Brad Bowman wrote:
> Michael G Schwern wrote:
>> FWIW name_lc() often pops up high in my profiles. Its called as part
>> of the
>> column stringification override which is called very, very often. So
>> yes, it
>> would be nice to optimize it away.
>>
>> There's probably no harm in simply changing the stringification sub to
>> be simply:
>>
>> sub { lc shift->name };
>>
>> That would remove a layer of method calls.
You could remove yet another layer of method calls, and an overloaded operator
call, by changing all uses of a column as a string inside CDBI to a method
call. Overloading is slow, nearly as bad as tying.
Rate overload method
overload 965480/s -- -50%
method 1949590/s 102% --
A simple way to find them all is to remove the operator overload from
CDBI::Column and run the test suite. Then fill in the blanks. Alternatively,
add a carp() to the string overload.
_______________________________________________
ClassDBI mailing list
ClassDBI-Ra3b/[email protected]
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi
overload_bench.plx
(text/plain, 438 B)
#!/usr/bin/perl -w
use strict;
{
package Parent;
sub new { bless \$_[1], $_[0] }
}
{
package Foo;
use base qw(Parent);
use overload q[""] => sub { ${$_[0]} };
}
{
package Bar;
use base qw(Parent);
sub string { ${$_[0]} }
}
use Benchmark ':all';
my $overload = Foo->new("Something");
my $method = Bar->new("Something");
cmpthese( shift || -3, {
overload => sub { "$overload" },
method => sub { $method->string },
});