I have 2 text files. I want to find the frequency of a letter(eg: "L") in both of them. Is there a way to apply ThreadPoolExecutor or ProcessPoolExecutor to make this faster?
So far I've tried it's only increasing the time taken.
def countFreq(data):
res = {i : data.count(i) for i in set(data)}
print(res)
This is the frequency count function I'm using. I've converted the text files to string too.
#Normal method
start = time.time()
countFreq(str1)
countFreq(str2)
end = time.time()
print(f"Time taken: {end-start:.5f} seconds\n")
The above one is faster than the below code, why is that
#Method multiprocessing
start = time.time()
p1 = multiprocessing.Process(countFreq(str1))
p2 = multiprocessing.Process(countFreq(str2))
p1.start()
p2.start()
p1.join()
p2.join()
end = time.time()
print(f"Time taken: {end-start:.5f} seconds\n")
Any ideas on how to run them faster? Is it an IO-related or a processing-related issue?