I've done some benchmarking of my own over various dataset
sizes.
| dataset size | Grep | Max | Ternary |
| 100 | 319704.72/s | 167783.44/s | 160956.63/s |
| 1000 | 324017.59/s | 158933.12/s | 157394.83/s |
| 10000 | 328377.50/s | 162308.63/s | 159661.13/s |
| 100000 | 332964.44/s | 160964.22/s | 157891.99/s |
You will notice that the times for dataset sizes of 100,
1000, 10000 and 100000 are nearly identical for each algorithm.
This clearly shows that for datasets of that size
it is not the size of the dataset that is the limiting factor
in performance.
I suspect the preformance issue is "Algorithmic Friction";
the overhead involved in doing the calls themselves.
Also remember that the sort
is implemented in the C library, so it is really fast.
(still O(n log(n)), but a very fast O(n log(n))).
What I expect you're seeing is that it is much quicker to
sort (implemented in binary code) and index
the last element than it is to iterate through an array (even once)
in an interpreted language for datasets of the size we are considering.
You see similar results with sorting algorithms.
Quicksort is well know to be the fastest general
purpose sorting
algorithm for large sets O(n log(n)). However
the overhead incurred by quicksort is
overkill for small datasets. For datasets with very few
elements bubblesort is often faster, even though bubble
sort is O(n^2).
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.