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