Hi guys!
I have to make an application for which the running time is really important, and to summarize I have 2 text files (one really huge: 80MB and the other of 1.6 MB). Those 2 files contain information for more than 1500 locations, and I have to produce 1 file per location with both of these files' data.
I have been using Perl for a little while now and I usually copy the file into an array to manipulate it (though I am just getting out of my engineering school so I still have a lot to learn...). So that's what I am doing for the 2 input files. (opening file, getting the data into an array with one line per cell, closing the file)
Then I am creating an array representing one output file and once the treatment is completed(I need to make some change to the data too once I get it ) I open a file, print the array, close the file...that makes a lot of I/O interactions... Maybe I must precise that the access is not sequential for now (the way I thought the algorithm) and I am doing that type of action to reach the data I want in the huge array:
.....
$lineNum=$specStartL+$timeStepNum*($nLocs*($nFreq+2)+1)+($pointN-1)*($nFreq+2);# to access the right line directly
$swanSpec[$lineNum]=~/(\S+)/;
....
# each line has many numbers I need to manipulate, so I am then creating a temporary array with those numbers in each cell for each line...
my @temp= split /\s+/,$swanSpec[$lineNum];
shift(@temp);
print "temp" if ($test==1);
#&printArray(\@temp) if ($test==1);
return \@temp;
.......
Though If you think it would be faster with sequential access I can maybe do that but I would have a version of each output array at the same time which would use a big amount of memory too...
Also those files gonna be twice as big in a few weeks...or I can maybe produce more of these type of input files and obviously smaller, would that help?
Would you have any idea on how to make it run faster?
Let me know if you need some more information about the code!
As I said I am just getting out of school and I have been learning how to code in Perl on my own in my various internships.. so I am not sure of what is real good perl code and what is not... would you have any web site to advise me too for efficiency programming?
Finally, I hope I have been clear enought and please forgive me my language mistakes, I am french...
Thanks a lot!
Have a wonderful day!
I have to make an application for which the running time is really important, and to summarize I have 2 text files (one really huge: 80MB and the other of 1.6 MB). Those 2 files contain information for more than 1500 locations, and I have to produce 1 file per location with both of these files' data.
I have been using Perl for a little while now and I usually copy the file into an array to manipulate it (though I am just getting out of my engineering school so I still have a lot to learn...). So that's what I am doing for the 2 input files. (opening file, getting the data into an array with one line per cell, closing the file)
Then I am creating an array representing one output file and once the treatment is completed(I need to make some change to the data too once I get it ) I open a file, print the array, close the file...that makes a lot of I/O interactions... Maybe I must precise that the access is not sequential for now (the way I thought the algorithm) and I am doing that type of action to reach the data I want in the huge array:
.....
$lineNum=$specStartL+$timeStepNum*($nLocs*($nFreq+2)+1)+($pointN-1)*($nFreq+2);# to access the right line directly
$swanSpec[$lineNum]=~/(\S+)/;
....
# each line has many numbers I need to manipulate, so I am then creating a temporary array with those numbers in each cell for each line...
my @temp= split /\s+/,$swanSpec[$lineNum];
shift(@temp);
print "temp" if ($test==1);
#&printArray(\@temp) if ($test==1);
return \@temp;
.......
Though If you think it would be faster with sequential access I can maybe do that but I would have a version of each output array at the same time which would use a big amount of memory too...
Also those files gonna be twice as big in a few weeks...or I can maybe produce more of these type of input files and obviously smaller, would that help?
Would you have any idea on how to make it run faster?
Let me know if you need some more information about the code!
As I said I am just getting out of school and I have been learning how to code in Perl on my own in my various internships.. so I am not sure of what is real good perl code and what is not... would you have any web site to advise me too for efficiency programming?
Finally, I hope I have been clear enought and please forgive me my language mistakes, I am french...
Thanks a lot!
Have a wonderful day!