CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
speed up perl code

 



cibien
Novice

Sep 19, 2012, 2:20 AM

Post #1 of 3 (6299 views)
speed up perl code Can't Post

Hi, I make this perl code (convert excel files in one xml file), it works well but is too much slow, 4 minute to create the xml file (12mb). Can you help me to modify this perl code to speed up the conversion?

thanks Smile

Andrea
Attachments: perl code.txt (52.6 KB)


FishMonger
Veteran / Moderator

Sep 19, 2012, 7:10 AM

Post #2 of 3 (6292 views)
Re: [cibien] speed up perl code [In reply to] Can't Post

Start by adding the strict and warnings pragmas and remove the -w switch. Those pragmas should be in every script you write.

Code
use strict; 
use warnings;


Run your code thru Perl::Tidy to fix the formatting. Your improper use of indentation makes it harder to follow the flow of the code.
http://search.cpan.org/~shancock/Perl-Tidy-20120714/lib/Perl/Tidy.pm

Use Perl's for loop style instead of the C style for loop. Perl's style is not only cleaner, it executes faster.

Your repeated calls to decode() on the same cell value is wasteful. Call it once and assign it to a var that is used when checking/testing for different values.

Use Devel::NYTProf to profile your code to see where it's spending its time and thus know what sections need to be reworked.
http://search.cpan.org/~timb/Devel-NYTProf-4.09/lib/Devel/NYTProf.pm

Refactor sections of the code into subroutines. Having the entire script in an 800 line block is a sign of poor design.


cibien
Novice

Oct 9, 2012, 7:53 AM

Post #3 of 3 (4889 views)
Re: [FishMonger] speed up perl code [In reply to] Can't Post

thanks for your advice, with Devel::NYTProf,

I understand that it speding a lot of time here:

" while( ($filename = readdir(DIR))){ "

the module Spreadsheet::ParseExcel spend a lot of time to open the excel file...

Is fast to open light .xls files, and very slow to open big (4mb) .xls files

I think is nothing to do.

thankyou

Andrea

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives