Re: Hm. ItemFactory vs. gtk2-perl 0.90 ? :)

On Tue, 2003-07-22 at 18:15, Chas Owens wrote:
Quoting Joe Smith <jes martnet com>:
I took a shot at avoiding all the copying to a bunch of local variables;
the guts of it, as tested in the benchmark, are as fast as Ross' or 
faster (see the attached diff).  Hah!

Cheating! Cheating!  The variable @j2_keys is empty when the function is called
(it doesn't get filled until AFTER the benchmarks run, you need a BEGIN {}). 
You moved code out of the function.  You should allow the brett function to use
that variable as well and your error message is not equivalent.  And still you
only beat the ross function in the fourth case -- which is the unlikely
"everything is wrong" case.

this code:

my @j2_keys;
my $j2_entry;
        @j2_keys = qw(path accelerator callback action item_type extra type);
        $j2_entry = {};

sub joe2 {
       my $user_entry = shift;
       @$j2_entry{ j2_keys} = @$user_entry{ j2_keys};
       my @bad = grep(!exists $j2_entry->{$_}, keys %$user_entry);
       foreach (@bad)
        carp("Gtk Item Factory Entry; unknown key ($_) ");

the foreach bad code is much like brett's code, except that there's the
local array bad, if you're trying to get rid of local vars then remove
the my @bad and put that in the foreach. doing this made no noticeable
difference in the performance. i assume that @bad = grep, foreach (bad)
and foreach (grep) both end up in a local var, it's just whether you put
a name to it or not, same as foreach my $key () or foreach ().

doing the above and changing all of the error message to print the same
sentence for each bad key makes the playing field level. (as far as i
can tell.)


         Rate brett  joe2   joe  ross
brett 14309/s    --  -30%  -31%  -49%
joe2  20484/s   43%    --   -1%  -28%
joe   20678/s   45%    1%    --  -27%
ross  28284/s   98%   38%   37%    --
         Rate brett  joe2   joe  ross
brett 13743/s    --  -29%  -29%  -46%
joe2  19265/s   40%    --   -1%  -25%
joe   19486/s   42%    1%    --  -24%
ross  25603/s   86%   33%   31%    --
         Rate brett   joe  joe2  ross
brett 19121/s    --  -28%  -42%  -55%
joe   26429/s   38%    --  -20%  -38%
joe2  33154/s   73%   25%    --  -22%
ross  42290/s  121%   60%   28%    --
         Rate brett  joe2   joe  ross
brett 12442/s    --  -27%  -31%  -36%
joe2  17014/s   37%    --   -5%  -12%
joe   17926/s   44%    5%    --   -8%
ross  19425/s   56%   14%    8%    --

this has been interesting if nothing else. the whole reason i learned xs
stuff in the first place is that somethings need to get down to where
there's plenty of speed available, image processing etc, it's always
good/interesting to try a bunch of stuff and see what cost what in terms
of performance. 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]