[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-Toolbox] QuickDraw and MacWindows



On Wed, Jun 28, 2000 at 10:58:52AM +0100, Alan Fry wrote:
> At 6:43 pm -0400 27/06/00, Quentin Smith wrote:
> 
> >I think my mailer messed up, as those typos were not there. I can assure
> >you, with the modifications I made, it works fine. Here's a complete version
> >of the EasyWindow module with my modifications:
> 
> My local dial-up connection here in the middle of nowhere degenerates 
> into two tin cans and a piece of string, so maybe that is where the 
> problem arose.
> 
> Sorry, I misunderstood your intention -- in particular the 'sub { &{ 
> $draw }' line. Sure, that works fine. I think we're in TMTOWTDI 
> country now.
> 
> However I suspect your version suffers from the same drawback as my 
> original version that the eval() gets called every update; because 
> when the subroutine &{$draw} is called it in turn calls the eval() in 
> '$draw = eval "sub {$str}"'.

In the code snippet

  $draw = eval "sub {$str}";
  &$draw; &$draw; &$draw;

eval is called only once.


But, this line:

    $win->sethook('redraw', sub { &{ $draw } });

could be rewritten as:

    $win->sethook('redraw', $draw);


> However, does it really matter? I simply don't know what the 
> penalties in terms of speed or memory might be in repeatedly running 
> an eval(). One has a feeling there probably is a price to pay but I 
> have no idea how to measure the effect.

Benchmark.pm?


#!/usr/local/bin/perl

use Benchmark;

$sub = 'sub { $_[0] = ($_[0] + 1) % 10 }';
my $once = eval $sub;

$x = 0;

timethese(1 << shift,
          {
           once => sub { &$once($x) },
           many => sub { $many = eval $sub; &$many($x) },
          }
         );

__END__


Benchmark: timing 32768 iterations of many, once...
      many: 15 wallclock secs (13.48 usr +  0.03 sys = 13.51 CPU)
      once:  0 wallclock secs ( 0.40 usr +  0.00 sys =  0.40 CPU)


Benchmark: timing 32768 iterations of many, once...
      many: 11 wallclock secs (11.03 usr +  0.02 sys = 11.05 CPU)
      once:  1 wallclock secs ( 0.27 usr +  0.01 sys =  0.28 CPU)
            (warning: too few iterations for a reliable count)


So you might say that there is a noticeable difference.


Ronald

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-toolbox-request@macperl.org