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



Chas Owens wrote:
I am just the sort of person who has to run a benchmark.

[ ... fudged data snipped with extreme prejudice ... ]

Oh, now you've done it.  This means war!

(This is why my productivity in Perl just sucks; not only is there more than one way to do it, I have to re-write and tweak until I'm sure I've tried *all* of them)

It looks like the simple if based switch cleans the other methods clocks.  That
being said,  Joe's makes it easy to add new keys and to alias keys (type and
item_type can both point to $item), but the keys for this function are already
written in stone (the Gtk API).  I can't see a reason not to use the fastest
function in this case (since there will be little to no maintenance).

I looked at the Gtk2.pm code, and I completely agree. There is nothing wrong at all with Ross' implementation. I wouldn't spend any time trying to 'clean this up' ... but that never stopped me yet!

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!

Here are the figures I got (yes, my computer is slow and busy with other stuff):

         Rate brett   joe  joe2  ross
brett  7778/s    --  -33%  -48%  -52%
joe   11676/s   50%    --  -21%  -28%
joe2  14861/s   91%   27%    --   -9%
ross  16317/s  110%   40%   10%    --
         Rate brett   joe  ross  joe2
brett  6957/s    --  -20%  -49%  -53%
joe    8723/s   25%    --  -37%  -41%
ross  13743/s   98%   58%    --   -7%
joe2  14817/s  113%   70%    8%    --
         Rate brett   joe  joe2  ross
brett 10099/s    --  -29%  -45%  -55%
joe   14250/s   41%    --  -22%  -36%
joe2  18383/s   82%   29%    --  -18%
ross  22329/s  121%   57%   21%    --
         Rate   joe brett  ross  joe2
joe    4744/s    --  -17%  -54%  -68%
brett  5708/s   20%    --  -44%  -61%
ross  10274/s  117%   80%    --  -30%
joe2  14768/s  211%  159%   44%    --

I went ahead and re-wrote the wrapper as well; anyone foolish enough to spend yet more time on this can get it here: http://pcsb620.tju.edu/~jes/ItemFactory.pm

Again, I'm NOT recommending this as better than the current, or better than Ross' in any terribly meaningful way. It's mostly just frobbing around.

<Joe
--- bench.pl.orig       2003-07-22 16:40:54.000000000 -0400
+++ bench.pl    2003-07-22 17:00:17.000000000 -0400
@@ -44,6 +44,7 @@
                {
                        ross   => sub { ross  ($set[$run]) },
                        joe    => sub { joe   ($set[$run]) },
+                       joe2   => sub { joe2  ($set[$run]) },
                        brett  => sub { brett ($set[$run]) },
                }
        );
@@ -113,6 +114,16 @@
        }
 }
 
+my @j2_keys = qw(path accelerator callback action item_type extra   type);
+my $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);
+       carp("invalid entry item(s): @bad") if @bad;
+}
+
 sub brett {
        my $entry = shift;
        my @keys = qw(


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