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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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



Sep 19, 2012, 2:20 AM

Post #1 of 3 (11351 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

Attachments: perl code.txt (52.6 KB)

Veteran / Moderator

Sep 19, 2012, 7:10 AM

Post #2 of 3 (11344 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.

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.

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.

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


Oct 9, 2012, 7:53 AM

Post #3 of 3 (9941 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.




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

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