Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comparing Tcl::Tk and perlTk WRT speed

by Courage (Parson)
on Jan 28, 2005 at 19:50 UTC ( [id://426089]=perlmeditation: print w/replies, xml ) Need Help??

It appears that Tcl::Tk is faster than perl/Tk
Tcl::Tk must be at least version 0.86

Consider following "stress-test" code, at first perlTk:

use Tk; my $mw = tkinit; my $tw = $mw->Scrolled('Text')->pack; my $t0=time; for my $stresser ('a'..'zzz') { $tw->windowCreate('end',-window=>$tw->Button(-text=>$stresser)); if ($stresser =~ /z$/) { $tw->insert('end',"\n") ; $tw->see('end'); #$tw->update; } } my $t1=time; print STDERR "time=".($t1-$t0)."\n"; MainLoop;
It does simple but numerous action: it inserts a number similar buttons into Text widget. On my slow PC it reports execution time of 52sec.
It appears that similar Tcl::Tk code executes almost twice as fast, 28sec:
use Tcl::Tk qw(:perlTk); my $mw = tkinit; my $tw = $mw->Scrolled('Text')->pack; my $t0=time; for my $stresser ('a'..'zzz') { $tw->windowCreate('end',-window=>$tw->Button(-text=>$stresser)); if ($stresser =~ /z$/) { $tw->insert('end',"\n") ; $tw->seeEnd; #$tw->update; } } my $t1=time; print STDERR "time=".($t1-$t0)."\n"; MainLoop;
Additionally, Tcl::Tk has special consideration of faster invocation of widgets methods, when no preprocessing needed; this approach saves another 20%, so finishing in 23sec:
use Tcl::Tk qw(:perlTk); my $mw = tkinit; my $tw = $mw->Scrolled('Text')->pack; my $t0=time; for my $stresser ('a'..'zzz') { $tw->_windowCreate('end',-window=>$tw->_Button(-text=>$stresser)); if ($stresser =~ /z$/) { $tw->_insert('end',"\n") ; $tw->_seeEnd; #$tw->update; } } my $t1=time; print STDERR "time=".($t1-$t0)."\n"; MainLoop;
In order to gain better execution speed, it is possible to compile Tcl/Tk binaries into Tcl::Tk module and to use common with Perl memory allocator, but this could be subject for deeper meditation.

My PerlTk installation is that one coming with ActiveState's build of both Linux and Windows perls, Tcl::Tk I built for myself...

Memory consumption is on Tcl::Tk side also better.

PS. why this stupid dog did not used Benchmark? Okay, if this is essential, I'll do deeper investigation in reply to first person who interested in that

Replies are listed 'Best First'.
Re: Comparing Tcl::Tk and perlTk WRT speed
by bart (Canon) on Jan 29, 2005 at 21:36 UTC
    PS. why this stupid dog did not used Benchmark?

    If you just use Time::HiRes 'time';, you already get a much higher resolution for the time measurements than you do now, without changing anything else in the code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://426089]
Approved by Aristotle
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-20 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found