I have a 30 megabyte .txt file with one line of data (30 million digits)
Unfortunately, every method I tried ( mmap.read() , readline() , allocating 1 GB of RAM, for loops) takes 45 minutes to read the file completely. Every method I found on the Internet seems to work on the fact that each line is small, so the memory consumption reaches as large as the largest line in the file. Here is the code I used.
start = time.clock() z = open('Number.txt','r+') m = mmap.mmap(z.fileno(), 0) global a a = int(m.read()) z.close() end = time.clock() secs = (end - start) print("Number read in","%s" % (secs),"seconds.", file=f) print("Number read in","%s" % (secs),"seconds.") f.flush() del end,start,secs,z,m
In addition to dividing numbers from one line into different lines; which I would prefer not to do, is there a cleaner method that won't take most of an hour?
By the way, I do not have to use text files.
I have: Windows 8.1 64-bit, 16 GB RAM, Python 3.5.1
source share