Algorithm-Heapify-XS

 view release on metacpan or  search on metacpan

t/max_heap.t  view on Meta::CPAN

# Before 'make install' is performed this script should be runnable with
# 'make test'. After 'make install' it should work as 'perl Algorithm-Heapify-XS.t'

#########################
use strict;
use warnings;

use Devel::Peek;
use Data::Dumper;

package OloadAry {
    use strict;
    use warnings;
    my $called= 0;
    use overload
        '<=>' => sub {
            $called++;
            my ($l,$r,$swap)= @_;
            ($l,$r)= ($r,$l) if $swap;

t/max_heap.t  view on Meta::CPAN

            push @sequence1, "$agent:$job_id";
        }
    }
    $max_heap_elapsed += time();
    my $max_heap_comparisons= OloadAry::reset_called_count();
    
    my $sort_elapsed= 0 - time();
    {
        @$_= sort { $b <=> $a } @$_ for @arrays2;
        @arrays2= sort { $b <=> $a } @arrays2;
        #die Data::Dumper::Dumper(\@arrays2);
        my %taken;
        while (@arrays2) {
            my $best_ary= shift @arrays2;
            last if !@$best_ary;
            my $best_item= shift @$best_ary;
            my $agent= $agent_array{0+$best_ary};
            my $score= $best_item->[0];
            my $job_id= $best_item->[1];
            push @sequence2, "$agent:$job_id";
            $taken{$job_id}++;

t/min_heap.t  view on Meta::CPAN

# Before 'make install' is performed this script should be runnable with
# 'make test'. After 'make install' it should work as 'perl Algorithm-Heapify-XS.t'

#########################
use strict;
use warnings;

use Devel::Peek;
use Data::Dumper;

package OloadAry {
    use strict;
    use warnings;
    my $called= 0;
    use overload
        '<=>' => sub {
            $called++;
            my ($l,$r,$swap)= @_;
            ($l,$r)= ($r,$l) if $swap;

t/min_heap.t  view on Meta::CPAN

            push @sequence1, "$agent:$job_id";
        }
    }
    $min_heap_elapsed += time();
    my $min_heap_comparisons= OloadAry::reset_called_count();
    
    my $sort_elapsed= 0 - time();
    {
        @$_= sort { $a <=> $b } @$_ for @arrays2;
        @arrays2= sort { $a <=> $b } @arrays2;
        #die Data::Dumper::Dumper(\@arrays2);
        my %taken;
        while (@arrays2) {
            my $best_ary= shift @arrays2;
            last if !@$best_ary;
            my $best_item= shift @$best_ary;
            my $agent= $agent_array{0+$best_ary};
            my $score= $best_item->[0];
            my $job_id= $best_item->[1];
            push @sequence2, "$agent:$job_id";
            $taken{$job_id}++;



( run in 1.350 second using v1.01-cache-2.11-cpan-a5abf4f5562 )