I don't have much experience with perl/tk, but I'm using it for a script made to run on windows which gathers some data then creates and opens an html file with the output. The problem is that it's just too slow.

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(); }

In reply to Why so slow when using Perl/Tk? by RAS230

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.