If it were only sorting 100 records, it would take far less time.
Just as an aside, I have to reply to this paragraph with, of course, "Duh". :)
The 17 second difference between sorting 10e6 records containing just 100 values, with & without -u, is all down to only having to write 100 records to the final output file.
If that is your thesis, then you picked a really lousy experiment to test it. Luckily, it is easy to disprove.
perl -E"say int(rand(1e6)) for 1..1e6" | .\time .\sort >nul 3.65 user 3.73 user 3.65 user 0.07 system 0.07 system 0.09 system 7.63 elapsed 7.61 elapsed 7.57 elapsed perl -E"say int(rand(1e5)).9 for 1..1e6" | .\time .\sort >nul 3.56 user 3.48 user 3.40 user 0.07 system 0.18 system 0.12 system 5.17 elapsed 5.19 elapsed 5.21 elapsed perl -E"say int(rand(1e4)).99 for 1..1e6" | .\time .\sort >nul 3.32 user 3.37 user 3.34 user 0.04 system 0.06 system 0.06 system 4.97 elapsed 5.12 elapsed 4.96 elapsed perl -E"say int(rand(1e3)).999 for 1..1e6" | .\time .\sort >nul 3.17 user 3.09 user 3.20 user 0.07 system 0.09 system 0.06 system 4.79 elapsed 4.84 elapsed 4.82 elapsed perl -E"say int(rand(1e2)).9999 for 1..1e6" | .\time .\sort >nul 2.84 user 2.74 user 2.92 user 0.07 system 0.20 system 0.03 system 4.47 elapsed 4.62 elapsed 4.53 elapsed perl -E"say int(rand(10)).99999 for 1..1e6" | .\time .\sort >nul 2.57 user 2.54 user 2.46 user 0.09 system 0.03 system 0.06 system 4.07 elapsed 4.07 elapsed 4.09 elapsed perl -E"say int(rand(1)).999999 for 1..1e6" | .\time .\sort >nul 1.60 user 1.60 user 1.60 user 0.04 system 0.06 system 0.10 system 3.15 elapsed 3.16 elapsed 3.12 elapsed
Those runs all lack "-u" and so all have identical amounts of I/O and identical numbers of records to sort. The only difference is how many duplicates are present. Clearly, duplicates result in a non-trivial speed-up (even with a "dumb" implementation of "sort -u", one not even doing "-u") even at only 10x duplicates and not due to reduced I/O.
Is that really the only application of unique in the source code? If so, don't you also find it sadly dumb that the routine that wrote to those files that are to be merged didn't also trivially avoid writing duplicates?
- tye
In reply to Re^7: In-place sort with order assignment (data)
by tye
in thread In-place sort with order assignment
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |