Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I wrote two very simple scripts, one in wxPerl, the other in Win32::GUI as will be shown below. They basically do the same thing, i.e. open a fairly large text file (30MB), takes the query input from the textbox, search the text file using the query and display relevant results if any in another textbox. I've noticed the wxPerl version is generally much slower (about 7 seconds or more) than the Win32-GUI version.

I'm wondering if this is just normal (I'm not sure if the problem is reproducible but I think so) or if something can be done to improve the speed of the wxPerl version.

==Win32-GUI version==

use strict; use warnings; use Win32::GUI(); my $window = new Win32::GUI::DialogBox( -width => 520, -height => 580, ); $window->Show(); my $entry = $window->AddTextfield( -size => [440,25], ); $entry->SetFocus; my $button = $window->AddButton( -name => 'button', -text => 'Search', -left => 448, -size =>[60,25], -ok => 1, ); my $display_field = $window->AddTextfield( -top => 30, -size => [513,513], -vscroll => 1, -multiline => 1, ); Win32::GUI::Dialog; sub button_Click { my $now = time; my $file = "./data"; #text file about the size of 30 MB open my $data, '<', $file or die "Open failed: $!"; $display_field->SelectAll(); $display_field->Clear(); my $query = $entry->Text; while (<$data>) { $display_field->Append($_) if /$query/i; } $now = time - $now; my $time = sprintf("\r\nTotal running time: %02d:%02d:%02d\r\n", int( +$now / 3600), int(($now % 3600) / 60), int($now % 60)); $display_field->Append($time); }

==wxPerl version==

use strict; use warnings; use Wx qw(:everything); my ($window, $entry, $display_field); package MyApp; use base 'Wx::App'; use Wx qw(:everything); sub OnInit { $window = Wx::Frame->new( undef, -1, '', [0,0], [520,580], ); $entry = Wx::TextCtrl->new( $window, -1, "", [0, 0], [408,-1], ); my $button = Wx::Button->new( $window, -1, "Search", [428,0], ); $display_field = Wx::TextCtrl->new( $window, -1, "", [0, 30], [508,513], wxTE_MULTILINE, ); Wx::Event::EVT_BUTTON( $button, -1, \&button_click,); sub button_click { my $now = time; #text file encoded in GB2312 about the size of 30 MB... #containing English and Chinese characters my $file = "./data"; open my $data, '<', $file or die "Open failed: $!"; $display_field->Clear; $display_field->Update; my $query = $entry->GetValue(); while(<$data>){ if(/$query/i){ $display_field->AppendText($_); $window->Update; } } $now = time - $now; my $time = sprintf("\n\nTotal running time: %02d:%02d:%02d\n\n", int +($now / 3600), int(($now % 3600) / 60), int($now % 60)); $display_field->AppendText($time); } $window->Show; } MyApp->new->MainLoop;
Evironment: StrawberryPerl 5.10.1 WinXP SP3(Chinese Simplified) Intel Core 2 T5200 CPU 1G memory

UPDATE

Thanks to GrandFather and @Anonmous Monk, I'm beginning to suspect that it might also have something to do with character encoding. I just wrote a Tk version and it runs *about as fast* as the Win32::GUI version but the Chinese characters contained in the file are garbled. I'll keep the post updated. Thanks.

UPDATE2

Just wrote a simple Tk version. It runs about as fast as the Win32::GUI. I'm thinking maybe the problem I'm experiencing is somehow related to character encoding. The following is a Tk version.
use Tk; use strict; use warnings; my $window = MainWindow -> new(); $window->geometry("520x580"); my $entry_frame = $window -> Frame()->pack(-side => "top"); my $entry = $entry_frame -> Entry (-width => 53, ) -> pack(-side => 'l +eft'); $entry -> bind('<Return>'=> \&button_Click); $entry -> focus; my $button = $entry_frame -> Button (-text => "Search", -command => \& +button_Click ) -> pack (-side => 'right'); my $display_field = $window -> Scrolled("Text",-scrollbars => 'e', ) - +> pack(-side => 'top',-fill => 'y', -expand => 1); sub button_Click { my $now = time; my $file = "./data"; #text file about the size of 30 MB open my $data, '<', $file or die "Open failed: $!"; $display_field->delete('0.0','end'); my $query = $entry->get(); while (<$data>) { if(/$query/i){ $display_field->insert("end",$_); $window->update; } } $now = time - $now; my $time = sprintf("\n\nTotal running time: %02d:%02d:%02d\n\n +", int($now / 3600), int(($now % 3600) / 60), int($now % 60)); $display_field->insert('end',$time); } MainLoop;

Update3

Just found the Tk version runs about as fast as the Win32::GUI when all Chinese characters in the data file become garbled. And if I resave the data file as utf8 or use the following file open argument:
my $file = "./data"; #text file about the size of 30 MB open my $data, '<:encoding(euc-cn)', $file or die "Open failed: $! +";
, all the Chinese characters contained in the data file will display properly but at the same time the speed suffers significanly and the Tk version will run just as slow as the wxPerl version.

Conclusion (?)

Win32::GUI is faster than wxPerl in my case perhaps because the data file used in my case contains both English and Chinese characters and the Chinese characters get displayed much faster on screen when using the native API of a Chinese system.

Another Test

This time I deleted all Chinese characteres contained in the 30MB data file, and then I tried wxPerl, Win32::GUI and Tk versions again. The result is this:

Tk is about as fast as Win32::GUI

wxPerl is still slower than Win32::GUI. In my previous test, it was about 7-8 seconds slower, but now the gap narrows to 3-4 seconds.


In reply to Why is wxPerl slower than Win32GUI? by ZJ.Mike.2009

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-24 02:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found