I'm increasingly using python instead of perl but have one problem: always when I want to process large files (>1GB) line by line python seems to take ages for a job that perl does in a fraction of the time. However, the general opinion on the web seems to be that python should be at least as fast for text processing as perl. So my question is what am I doing wrong?
Example:
Read a file line by line, split the line at every tab and add the second item to a list. My python solution would look something like this:
with open() as infile:
for line in infile:
ls = line.split("\t")
list.append(ls[1])
The perl code would look like this:
open(my $infile,"<",file_path);
while(my $line=<$infile>){
my @ls = split(/\t/,$line);
push @list, $ls[1]
}
close($infile)
Is there any way to speed this up?
And to make it clear: I don't want to start the usual "[fill in name of script language A] is sooo much better than [fill in script language B]" thread. I'd like to use python more by this is a real problem for my work.
Any suggestions?