Re: Sort::Maker - benchmark
- From: Uri Guttman <uri@xxxxxxxxxxxxxxx>
- Date: Tue, 05 Dec 2006 18:29:37 -0500
"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
.
- Follow-Ups:
- Re: Sort::Maker - benchmark
- From: Uri Guttman
- Re: Sort::Maker - benchmark
- References:
- Sort::Maker : anonymous sub is compiled outside of my module
- From: Mumia W. (reading news)
- Sort::Maker - benchmark
- From: Gunnar Hjalmarsson
- Sort::Maker : anonymous sub is compiled outside of my module
- Prev by Date: Sort::Maker - benchmark
- Next by Date: Re: Sort::Maker - benchmark
- Previous by thread: Sort::Maker - benchmark
- Next by thread: Re: Sort::Maker - benchmark
- Index(es):
Relevant Pages
|
|