List-Insertion
view release on metacpan or search on metacpan
benchmark/bench.pl view on Meta::CPAN
use List::Insertion {type=>"numeric", duplicate=>"left", accessor=>'->{value}'};
use constant DEBUG=>undef;
# test
my $max=10;
my $size=$ARGV[0]//10000;
my @list=sort {$a->{value} <=> $b->{value} } map {{value=>rand($max)}} 1..$size;
my @keys=map rand($max), 1..10;
use feature ":all";
cmpthese DEBUG ? 1 : -1, {
"L::BS::PP"=>sub {
my @res=map List::BinarySearch::PP::binsearch_pos(sub {$a->{value} <=> $b->{value}}, {value=>$_}, @list), @keys;
if(DEBUG){
say "L::BS::PP";
say Dumper @res;
}
benchmark/build-sorted.pl view on Meta::CPAN
# Benchmark inserting a new element into the correct position in an existing
# sorted list
#
use strict;
use warnings;
use feature ":all";
use Data::Dumper;
use List::Insertion {type=>"numeric", duplicate=>"left", accessor=>'->{value}'};
use Benchmark qw<cmpthese>;
use List::BinarySearch::PP;# qw<binsearch_pos>;
use List::BinarySearch::XS;
use constant DEBUG=>undef;
my @data=map {{value=>rand(10)}} 1..$ARGV[0]//10;
cmpthese DEBUG ? 1 : -1, {
t/List-Insertion.t view on Meta::CPAN
use strict;
use warnings;
use feature ":all";
use Test::More;
BEGIN { use_ok('List::Insertion') };
use List::Insertion "make_search";
use List::Insertion {type=>"string"};
use List::Insertion {type=>"numeric", duplicate=>[qw<left right>]};
use List::Insertion {type=>"numeric", duplicate=>[qw<left right>], prefix=>"mysearch"};
use List::Insertion {type=>"numeric", duplicate=>[qw<left right>], prefix=>"hashsearch", accessor=>"->{key}"};
use List::Insertion {type=>"numeric", duplicate=>[qw<left right>], prefix=>"arraysearch", accessor=>"->[0]"};
( run in 0.915 second using v1.01-cache-2.11-cpan-cba739cd03b )