Created
June 6, 2009 15:24
-
-
Save mash/124881 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use List::Compare; | |
use Number::Interval; | |
use Benchmark qw/cmpthese/; | |
my ($min1,$max1) = (3,100); | |
my ($min2,$max2) = (20,130); | |
cmpthese( 1000, { | |
'list-compare' => sub { | |
my $lc = List::Compare->new( [ $min1..$max1 ], [ $min2..$max2 ] ); | |
my @intersection = $lc->get_intersection; | |
return scalar @intersection; | |
}, | |
'number-interval' => sub { | |
my $interval1 = new Number::Interval( Min => $min1, Max => $max1 ); | |
my $interval2 = new Number::Interval( Min => $min2, Max => $max2 ); | |
$interval1->intersection( $interval2 ); | |
return $interval1->max - $interval1->min; | |
}, | |
}); | |
creta% perl bench_number_range.pl | |
(warning: too few iterations for a reliable count) | |
Rate list-compare number-interval | |
list-compare 1124/s -- -97% | |
number-interval 33333/s 2867% -- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment