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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.