in reply to Re^6: read and sort multiple files
in thread read and sort multiple files
What extra open and closes? Grouping files greatly cuts down on the number of opens and closes.
In the case of a few small files, say 10 files, 100 of which fit in memory at a time.
Without grouping:
To sort: 2*10 opens
To merge: 3*(10-1) opens
Total: 47
With grouping:
To sort: 10 + ceil(10/100) opens
To merge: 3*(ceil(10/100)-1) opens
Total: 11
In the case of lots of small files, say 100 files, 10 of which fit in memory at a time.
Without grouping:
To sort: 2*100 opens
To merge: 3*(100-1) opens
Total: 497
With grouping:
To sort: 100 + ceil(100/10) opens
To merge: 3*(ceil(100/10)-1) opens
Total: 137
In the case of big files, it simply won't work without splitting.
You could cut down on the number of opens and closes by merging more than two files at a time, but it's not relevant here because it would apply to both grouping and non-grouping algorithms.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: read and sort multiple files
by matrixmadhan (Beadle) on Dec 06, 2008 at 14:52 UTC | |
by ikegami (Patriarch) on Dec 06, 2008 at 15:19 UTC |