Mindboggling. "qshuf", an N log N algorithm, shows to be 67 faster than any of linear algorithms, and you don't raise a flag?sub qshuf { sort { .5 <=> rand(1) } @_; } cmpthese(10, { slice => sub { slice @array }, xform => sub { xform @array }, shufl => sub { shufl @array }, qshuf => sub { qshuf @array }, }); Rate xform slice shufl qshuf xform 14.4/s -- -38% -70% -100% slice 23.3/s 61% -- -51% -99% shufl 47.8/s 232% 105% -- -99% qshuf 3284/s 22681% 14008% 6767% --
Your benchmark is extremely flawed. You're running your sort in void context. Perl, being smart, knows that sort in void context isn't going to do anything useful, so it's not going to work up a sweat, and just won't do anything.
Benchmark: timing 10000 iterations of qshuf, shufl, slice, xformHmmm, with a first argument of '10' to 'cmpthese'? Either your output doesn't match your program, or your Benchmark.pm module is different than mine.
In reply to Re^2: When the Best Solution Isn't
by Anonymous Monk
in thread When the Best Solution Isn't
by sauoq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |