Re: Sort::Maker - benchmark



"GH" == Gunnar Hjalmarsson <noreply@xxxxxxxxx> writes:

GH> Since this discussion started with this grep() solution:
GH> http://groups.google.com/group/comp.lang.perl.misc/msg/f02dee998cbac6d6

GH> i thought I'd do a benchmark. This is a typical result on my WinXP box
GH> for a 4 elements list:

GH> Rate S-Maker grep()
GH> S-Maker 2620/s -- -83%
GH> grep() 15769/s 502% --

GH> Break even as regards list size (besides the time for compiling
GH> Sort::Maker) seems to be around 20 elements:

GH> Rate grep() S-Maker
GH> grep() 1833/s -- -9%
GH> S-Maker 2014/s 10% --

that makes perfect sense. the win with the GRT is with larger input
sets. with only 4 elements the overhead will be slower than the actual
sort time. even with your code's O( N ** 2) growth it still does less
actual work for only 4 elements.


GH> This is the benchmark code:

GH> use Sort::Maker;
GH> use Benchmark 'cmpthese';

GH> sub build_data {
GH> my @r_order =
GH> map { ('_', 0..9, 'A'..'Z', 'a'..'z')[rand 63] } 1..shift;
GH> my @unsorted =
GH> map qq|<table><tr><td meascode="$_"></td></tr></table>|,
GH> @r_order;
GH> my @c_order;
GH> push @c_order, splice( @r_order, rand @r_order, 1 )
GH> while @r_order;
GH> join( '', @c_order ), @unsorted
GH> }

GH> my ($cost_order, @unsorted) = build_data(20);

GH> cmpthese( -5, {
GH> 'S-Maker' => sub {
GH> my $sorter = make_sorter(
GH> 'GRT',
GH> init_code => "my \$cost_order = '$cost_order';",
GH> signed => 1,
GH> string_data => 1,
GH> number => q{ /code="(.)"/ && index($cost_order,$1) },
GH> );
GH> my @sorted = $sorter->( @unsorted );

ahh, you are including the time to build the sort! factor that out (do
it before you call the benchmark) and then in here pass a wrapper sub
that calls the sorter on the data. you can't compare generating and
compiling the sorter sourse to your precompiled code.

this is why benchmarking is a skill unto itself. you have to know what
you are comparing and how to properly isolate the code under comparison.
sort::maker was designed to build a sorter once and reuse it many
times. you can either use the code ref or dump the source and cut/paste
it into your code and use it there. but that will break if i add the
closure feature as you can't paste in the private data from runtime. oh
well.

uri

--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.



Relevant Pages

  • Re: [fbsd] Re: (Another) simple benchmark
    ... default worker type for windows. ... While I agree this kind of benchmark is worth doing in order to compare ... performances of the Apache package and the underlying OS. ...
    (freebsd-performance)
  • Re: benchmarking FC1
    ... You want to compare different hardware plattforms with FC1 installed or ... don't think there are benchmark kits out for testing Gnome/KDE ... Fedora GNU/Linux Core 1 on Athlon CPU kernel 2.4.22-1.2149.nptl ...
    (Fedora)
  • Re: Fastcode CompareMem B&V
    ... > increased in each benchmark run, thus putting no pressure on the branch ... > on the number of bytes to compare. ... A compare should be terminated on matches and mismatches with 50% ... Deadline for 2005 B&V's was passed at 12/12. ...
    (borland.public.delphi.language.basm)
  • Re: My own small benchmark
    ... Didn't send it twice, sorry! ... Any benchmark is testing and comparing the systems on its overall ... I wanted to compare them by the efficiency, ... In some computer-magazins there are comparisions by needed ...
    (comp.lang.pascal.delphi.misc)
  • My own small benchmark
    ... Any benchmark is testing and comparing the systems on its overall ... I wanted to compare them by the efficiency, ... In some computer-magazins there are comparisions by needed ... power or TDP per GHz or something but tact per time? ...
    (borland.public.delphi.non-technical)