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

Re: [MacPerl-Toolbox] QuickDraw and MacWindows



At 10:33 am -0400 28/06/00, Quentin Smith wrote:

>What happens is something similar to this:
>$str = "print 'test'";
>$draw = eval "sub {$str}";
>foreach $i (1..100) {
>&{$draw};
># basically it is executing print 'test', which has been compiled up
># above at the eval.
>}

Yes, Quentin's right -- the eval() only runs once.

We ended up with three alternative working versions:

     sub DRAWING {
        my ($str) = @_;
        $draw = $str;                                 #version 1
        #eval "sub draw {$str}";                      #version 2
        #$draw = eval "sub { $str }";                 #Quentin's version
     }

     $win->sethook('redraw', sub { eval( $draw )});   #version 1
     #$win->sethook('redraw', \&draw);                #version 2
     #$win->sethook('redraw', sub { &{ $draw } });    #Quentin's version

Timing over 1000 'redraw's proves the point, yielding (per redraw):

     version 1		13.9 mS
     version 2		10.6 mS
     Quentin's version	10.6 mS

So it does matter -- to the extent of 40% of execution time. Interesting.

Alan Fry

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