RAS230 has asked for the wisdom of the Perl Monks concerning the following question:
I wrote up a quick example to show the problem. All the interface does is provide a button to start doing the work but even that seems to take 30-45 seconds each time it's run.
Half a minute plus might not even sound that bad, but the results are near instant if I run the same thing after commenting out all the perl/tk stuff. I'm willing to take a hit in performance in exchange for the simple interface, but this seems excessive. I'm wondering if the problem is just that I'm not using more perl/tk specific ways of doing the same things which might run much faster.
Like I said, I'm not very familiar with perl/tk, in fact this is only the second time I've used it for something, so please forgive me my ignorance and while your in a forgiving spirit, please forgive my example code (it's ugly but does show the problem).
#!perl -w use strict; require Tk; use Tk; my $row=1; my $filename="example_out.htm"; my %stuff1=( 'thing01_a' => "value01_a", 'thing02_a' => "value02_a", 'thing03_a' => "value03_a", 'thing04_a' => "value04_a", 'thing05_a' => "value05_a", 'thing06_a' => "value06_a", 'thing07_a' => "value07_a", 'thing08_a' => "value08_a", 'thing09_a' => "value09_a", 'thing10_a' => "value10_a" ); my %stuff2=( 'thing01_b' => "value01_b", 'thing02_b' => "value02_b", 'thing03_b' => "value03_b", 'thing04_b' => "value04_b", 'thing05_b' => "value05_b", 'thing06_b' => "value06_b", 'thing07_b' => "value07_b", 'thing08_b' => "value08_b", 'thing09_b' => "value09_b", 'thing10_b' => "value10_b" ); sub do_this() { open FILE, "> $filename" or die "ERROR WRITTING FILE: $filename\nSyste +m reported $!"; print FILE << "HTMLSTUFF"; <HTML> <HEAD><TITLE>TABLE O' STUFF</TITLE> <STYLE> table {border-style: solid;border-width: 2;border-color: #005A80;} td {padding:4px;border:0;text-align: center; white-space: nowrap} .header {background-color: #005A80;text-decoration: none;text-align: c +enter;color: white; font-weight: bold;} .line2 {background-color: lightblue;} .line1 {background-color: white;} </STYLE> </HEAD> <BODY> <P> <TABLE> <TR CLASS=header><TD>THING 1</TD> <TD>THING 2</TD> <TD>THING 3</TD> <T +D>THING 4</TD> <TD>THING 5</TD> <TD>THING 6</TD> <TD>THING 7</TD> <TD +>THING 8</TD> <TD>THING 9</TD> <TD>THING 10</TD></TR> HTMLSTUFF if ($row == 1) {print FILE "\n<TR CLASS=line1>"; $row=2;} elsif ($row +== 2) {print FILE "\n<TR CLASS=line2>"; $row=1;} foreach (sort keys(%stuff1) ) { print FILE "<TD CLASS=time>$stuff1{$_} +</TD>";} print FILE "</TR>"; if ($row == 1) {print FILE "\n<TR CLASS=line1>"; $row=2;} elsif ($row +== 2) {print FILE "\n<TR CLASS=line2>"; $row=1;} foreach (sort keys(%stuff2) ) { print FILE "<TD CLASS=time>$stuff2{$_} +</TD>";} print FILE "</TR>"; print FILE "\n</TABLE></BODY><HTML>"; close FILE; system "start /b $filename"; } my $fsize=12; my $main = MainWindow->new(); $main->title("Button Window"); $main->configure(-background=>'#c0c0c0'); $main->optionAdd('*BorderWidth' => 1); my $bottom = $main->Frame(-background=>'#c0c0c0')->pack(-expand=>0, -f +ill=>'both'); my $sub_button=$bottom->Button(-width=>40, -background=>"#c0c0c0", -fg +=>'black', -text=>'CLICK ME', -font => ['Courier', 10], -command=>\&c +lick); $sub_button->pack(-side => "bottom", -anchor => "s", -expand => "n", - +fill => "none"); MainLoop(); sub click() { do_this(); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Why so slow when using Perl/Tk?
by GrandFather (Saint) on Jul 29, 2009 at 00:09 UTC | |
Re: Why so slow when using Perl/Tk?
by BrowserUk (Patriarch) on Jul 28, 2009 at 22:59 UTC | |
by RAS230 (Acolyte) on Jul 29, 2009 at 00:37 UTC | |
by SuicideJunkie (Vicar) on Jul 29, 2009 at 12:38 UTC | |
Re: Why so slow when using Perl/Tk?
by ww (Archbishop) on Jul 28, 2009 at 22:28 UTC | |
by RAS230 (Acolyte) on Jul 28, 2009 at 22:54 UTC | |
by ww (Archbishop) on Jul 28, 2009 at 23:12 UTC | |
by RAS230 (Acolyte) on Jul 29, 2009 at 00:05 UTC | |
by Argel (Prior) on Jul 29, 2009 at 00:31 UTC | |
Re: Why so slow when using Perl/Tk?
by Argel (Prior) on Jul 28, 2009 at 23:04 UTC |