P.S. to the above post: grep should be slower than the other
two algorithms. Aighearach's
results were predictable,
where mine are distinctly opposite...
Update:
Having seen a few posts, I have to "update my version of
reality" (as a friend always chides me for doing slowly).
The grep sort implementation is running faster on
everyone else's machines, too. Algorithm analysis would
conclude that since sort is in O(N log N), it
should be slower than an O(N) algorithm (Max and
Ternary should both be in O(N)). Real-world
results don't show this.
What's going on? Somebody help me update my version of
reality! :-)
Here is what happens on my system:
Benchmark: timing 1000000 iterations of Grep, Max, Ternary...
Grep: 10 wallclock secs (10.75 usr + 0.05 sys = 10.80 CPU)
Max: 31 wallclock secs (31.10 usr + 0.05 sys = 31.15 CPU)
Ternary: 32 wallclock secs (31.29 usr + 0.01 sys = 31.30 CPU)
It is a dual PPro 200 (180, overclocked), RedHat 5.2
(seriously upgraded - 2.2.12 kernel).
perl -v says:
This is perl, version 5.005_57 built for i686-linux-thread
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.