#!/usr/bin/perl -w use strict; sub report { my($desc, $count, $sub) = @_; print STDERR "[[ timing ]] $desc\n"; print STDERR timestr(timeit($count, $sub))."\n"; } sub mark { print STDERR "------\n"; } my %options = @ARGV; srand(delete $options{srand}) if exists $options{srand}; defined(my $size = delete $options{size}) || die "No size option"; defined(my $class = delete $options{class}) || die "No class option"; defined(my $string = delete $options{string}) || die "No string option"; defined(my $dirty = delete $options{dirty}) || die "No dirty option"; defined(my $inc = delete $options{INC}) || die "No INC option"; die "Unknown option ", join(",", keys %options) if %options; @INC = map { s/%(\d+)/chr($1)/eg; $_ } split /:/, $inc; eval " use Benchmark; use $class; 1" || die $@; my $order = $string ? "lt" : "<"; my @input; if ($string) { for (1..$size) { push @input, {foo => "A" . rand(2*$size)} } } else { for (1..$size) { push @input, {foo => rand(2*$size)} } } my $heap = $class->new(elements => [Hash => "foo"], order => $order, dirty => $dirty); mark; report("Insert of $size elements into $class(order => '$order', Hash)", $size, sub { $heap->insert(pop @input) }); undef @input; report("Extract $size elements from $class(order => '$order', Hash)", $size, sub { $heap->extract_top });