3 points · by chirau · 7y ago · 4 comments
I have tried using Ordered for, CSV, itertools, buffers but it still seems I am not utilizing all resources available to me to make it even faster. I/O is ridiculously slow.
I have 32GB RAM and an Octacore setup. Should it really be taking me more than 10 min to process a single file? How best do i make sure I take full advantage of the memory and power of my machine?
What are you doing which is different from something like:
totals = []
for line in open(filename, "rb"):
fields = line.split()
totals.append(fields[2]) # or whatever
totals.sort()
... do something ..
or using collections.Counter() with open(filename, "rb") as f:
c = collections.Counter(line.split()[2] for line in f)
print(c.most_common(10))https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
(as you can see, Python is 50-100 times slower than C++)
Generally, it's hard to answer in abstract what the problem might be. Some starting points: You might be unnecessarily creating temporary objects - e.g. large lists. If you don't actually need csv parsing, the csv module might be slower than something simpler. A profiler might help you there. You can modify your program for multiple cores, but that's IMHO a later step once you got the baseline fast.