Any trick to speed up script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Any trick to speed up script?
# 1  
Old 02-21-2010
Any trick to speed up script?

Hi Guys,

I have a script that I am using to convert some text files to xls files. I create multiple temp. files in the process of conversion. Other than reducing the temp. files, are there any general tricks to help speed up the script?

I am running it in the bash shell.

Thanks.
# 2  
Old 02-21-2010
Post your code

Speeding up a script is not usually very easy to do without major rewrites. If you post some of your code here, we can offer better advice.
# 3  
Old 02-21-2010
In general:
  • Call as few things as possible. If you have a loop, watch the calls you make in it. A Useless Use Of Cat that happens 10,000 times isn't a trivial waste anymore. Often people call sed, awk, etc. for single strings, which can be a waste -- you might be able to refactor that, running sed once on a big chunk of data then reading the result into the shell piecewise instead of running sed 10,000 times. Or better yet, instead of making an external call for that:
  • Rely more on shell builtin functions. You can often use the shel builtin read and the IFS variable that controls it to replace things that call cut thousands of times, use shell expressions instead of a regex in sed, and so forth.
  • Limit the number of pipes. Each pipe represents another process that's either competing with you for CPU time, making your shell wait while it reads input, or making your shell wait before you can read its output. I wrote a homemade linewrapper in BASH that used at least six subshells feeding data into each other, that ended up processing text files at about 10 kilobytes per second.
  • Are there existing tools that can do what you want? A while ago there was a thread where someone needed to translate a giant single-line flat file. I wrote a solution in BASH that was horribly slow, then realized the file was so consistent I could just use dd with a few unusual options to convert it in no time flat.
# 4  
Old 02-21-2010
This may not help your situation but one additional thing I've found useful is backgrounding. If you have one section that you know will take much longer than other things, background some other things before running the long section, or vice versa. I recently had a 20+ second script that I was able to cut down to 7 seconds by backgrounding parts of it.
# 5  
Old 02-22-2010
another thing (not verified yet) is to use ramdisk (/dev/shm/) for your temp files.
# 6  
Old 02-22-2010
Quote:
Originally Posted by frans
another thing (not verified yet) is to use ramdisk (/dev/shm/) for your temp files.
That won't be any significant gain on a system with disk caching.
# 7  
Old 02-22-2010
Tools Something else to consider

Since Excel will open .csv files as spreadsheets, assuming you have no data issues (like comma's in your data), maybe just convert the text to csv file?
I know that at one place, I routinely created csv files that were emailed to people, and they would easily open the csv files into Excel.

Anyway, as someone else said, without seeing your script it is hard to advise.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to Speed up shell script

Hello, I am basic level shell script developer. I have developed the following script. The shell script basically tracking various files containing certain strings. I am finding options to make the script run more faster. Any help/suggestion would be appreciated :) #! /bin/bash # Greps for... (6 Replies)
Discussion started by: Bhanuprasad
6 Replies

2. Shell Programming and Scripting

Speed up the loop in shell script

Hi I have written a shell script which will test 300 to 500 IPs to find which are pinging and which are not pinging. the script which give output as 10.x.x.x is pining 10.x.x.x. is not pining - - - 10.x.x.x is pining like above. But, this script is taking... (6 Replies)
Discussion started by: kumar85shiv
6 Replies

3. Shell Programming and Scripting

Help me with speed up this script

hey guys i have a perl script wich use to compare hashes but it tookes a long time to do that so i wich i will have the soulition to do it soo fast he is the code <redacted> (1 Reply)
Discussion started by: benga
1 Replies

4. Shell Programming and Scripting

How can i speed this script up?

Hi, Im quite new to scripting and would like a bit of assistance with trying to speed up the following script. At the moment it is quite slow.... Any way to improve it? total=111120 while do total=`expr $total + 1` INCREMENT=$total firstline = "blablabla" secondline = "blablabla"... (5 Replies)
Discussion started by: brunlea
5 Replies

5. Shell Programming and Scripting

Slow Perl script: how to speed up?

I had written a perl script to compare two files: new and master and get the output of the first file i.e. the first file: words that are not in the master file STRUCTURE OF THE TWO FILES The first file is a series of names ramesh sushil jonga sudesh lugdi whereas the second file (could be... (4 Replies)
Discussion started by: gimley
4 Replies

6. Filesystems, Disks and Memory

data from blktrace: read speed V.S. write speed

I analysed disk performance with blktrace and get some data: read: 8,3 4 2141 2.882115217 3342 Q R 195732187 + 32 8,3 4 2142 2.882116411 3342 G R 195732187 + 32 8,3 4 2144 2.882117647 3342 I R 195732187 + 32 8,3 4 2145 ... (1 Reply)
Discussion started by: W.C.C
1 Replies

7. Shell Programming and Scripting

Speed up this script!

I have a script that processes a fair amount of data -- say, 25-50 megs per run. I'd like ideas on speeding it up. The code is actually just a preprocessor -- I'm using another language to do the heavy lifting. But as it happens, the preprocessing takes much more time than the final processing... (3 Replies)
Discussion started by: CRGreathouse
3 Replies

8. Shell Programming and Scripting

Help to improve speed of text processing script

Hey together, You should know, that I'am relatively new to shell scripting, so my solution is probably a little awkward. Here is the script: #!/bin/bash live_dir=/var/lib/pokerhands/live for limit in `find $live_dir/ -type d | sed -e s#$live_dir/##`; do cat $live_dir/$limit/*... (19 Replies)
Discussion started by: lorus
19 Replies

9. Shell Programming and Scripting

any way to speed up calculations in bash script

hi i have a script that is taking the difference of multiple columns in a file from a value from a single row..so far i have a loop to do that.. all the data is floating point..fin has the difference between array1 and array2..array1 has 700 x 300= 210000 values and array2 has 700 values.. ... (11 Replies)
Discussion started by: npatwardhan
11 Replies

10. Filesystems, Disks and Memory

dmidecode, RAM speed = "Current Speed: Unknown"

Hello, I have a Supermicro server with a P4SCI mother board running Debian Sarge 3.1. This is the "dmidecode" output related to RAM info: RAM speed information is incomplete.. "Current Speed: Unknown", is there anyway/soft to get the speed of installed RAM modules? thanks!! Regards :)... (0 Replies)
Discussion started by: Santi
0 Replies
Login or Register to Ask a Question