[tcltk-perl] overload stringification of widgets
Brought to you by:
hobbs
From: Vadim K. <va...@ar...> - 2004-05-08 06:47:29
|
As you may have noticed, I did a change to make for any widget to be its path when stringification occurs. so perl -MTcl::Tk -we "$i =Tcl::Tk::tkinit->Button->pack; print $i" outputs .btn01 Interesting to say, it required adding just one line to Tk.pm: use overload '""' => \&path; Now code from tk-demo like my $f_list = $f->Listbox; my $f_scroll = $f->Scrollbar(-command => [$f_list => 'yview']); works via stringification of $f_list. However, I wonder if there will be any consequences (I mean slowdown). If anyone notices this, please speak. Using "Benchmark.pm" Perl module: I commented line "MainLoop" in 'wdiget' from 'tk-demo' directory, and here it is: w/o overload: >perl -MBenchmark -e "timethis 100, sub{do 'widget0'}" timethis 100: 6 wallclock secs ( 5.28 usr + 0.59 sys = 5.87 CPU) @ 17.04/s (n=100) >perl -MBenchmark -e "timethis 300, sub{do 'widget0'}" timethis 300: 17 wallclock secs (15.12 usr + 1.27 sys = 16.39 CPU) @ 18.30/s (n=300) w/ overload: >perl -MBenchmark -e "timethis 100, sub{do 'widget0'}" timethis 100: 6 wallclock secs ( 5.38 usr + 0.56 sys = 5.94 CPU) @ 16.84/s (n=100) >perl -MBenchmark -e "timethis 300, sub{do 'widget0'}" timethis 300: 16 wallclock secs (15.19 usr + 1.19 sys = 16.38 CPU) @ 18.31/s (n=300) Now same with perlTk: widget0-ptk is 'widget' from distribution perlTk804-024, with three lines commented out: #use lib Tk->findINC('demos/widget_lib'); ... #use WidgetDemo; ... #MainLoop; perl -MBenchmark -e "timethis 100, sub{do 'widget0-ptk'}" timethis 100: 19 wallclock secs (17.70 usr + 1.41 sys = 19.11 CPU) @ 5.23/s (n=100) 300: timethis 300: 57 wallclock secs (51.57 usr + 4.61 sys = 56.18 CPU) @ 5.34/s (n=300) Best regards, Vadim. |