Surprising (for me) benchmark results...
Sean 'Shaleh' Perry
shaleh at valinux.com
Tue May 1 17:40:36 EDT 2001
>
> start = time.time()
> f = open("infile.txt", 'r')
> out = open("outfile.txt", 'w')
> l = f.readlines()
> l.sort()
> out.writelines(l)
> f.close()
> out.close()
> end = time.time()
>
> print (end-start), " seconds"
>
> Python runtime: 600 ms
>
realize that readlines() reads the entire file into memory, so the sort was
100% in memory.
On today's machines reading an entire 4.5 mb file is not that bad, but still
something to remember.
More information about the Python-list
mailing list