Ancient

 view release on metacpan or  search on metacpan

bench/all.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use List::Util ();
use util qw(all);

print "=" x 60, "\n";
print "all - All Match Benchmark\n";
print "=" x 60, "\n\n";

my @numbers = 1..1000;

print "=== All match ===\n";

bench/all_cmp.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use List::Util ();
use util qw(all_gt all_lt all_ge all_le all_eq all_ne);

print "=" x 60, "\n";
print "all_* - Specialized All Comparison Benchmark\n";
print "=" x 60, "\n\n";

my @numbers = 1..1000;

print "=== all_gt (all match) ===\n";

bench/all_slot_ops.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese :hireswallclock);

use lib 'blib/lib', 'blib/arch';
use slot;

# Create slots at compile time for optimization
use slot qw(bench_slot);

print "=" x 70, "\n";
print "Benchmark: All slot:: functions with call checker optimization\n";
print "=" x 70, "\n\n";

bench_slot(42);

bench/always.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(always);

print "=" x 60, "\n";
print "always - Constant Function Benchmark\n";
print "=" x 60, "\n\n";

# Pure Perl always
sub pure_always {
    my $val = shift;
    return sub { $val };

bench/any.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use List::Util ();
use util qw(any);

print "=" x 60, "\n";
print "any - Any Match Benchmark\n";
print "=" x 60, "\n\n";

my @numbers = 1..1000;

print "=== Match in middle ===\n";

bench/any_cmp.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use List::Util ();
use util qw(any_gt any_lt any_ge any_le any_eq any_ne);

print "=" x 60, "\n";
print "any_* - Specialized Any Comparison Benchmark\n";
print "=" x 60, "\n\n";

my @numbers = 1..1000;

print "=== any_gt ===\n";

bench/bool.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(is_true is_false bool);

print "=" x 60, "\n";
print "Boolean Predicates Benchmark\n";
print "=" x 60, "\n\n";

my $truthy = 42;
my $falsy = 0;
my $undef = undef;

bench/clamp.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(clamp);

print "=" x 60, "\n";
print "clamp - Range Constraint Benchmark\n";
print "=" x 60, "\n\n";

# Pure Perl clamp
sub pure_clamp {
    my ($val, $min, $max) = @_;
    return $val < $min ? $min : $val > $max ? $max : $val;

bench/collections.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(is_empty_array is_empty_hash array_len hash_size array_first array_last hash_has);

print "=" x 60, "\n";
print "Collection Operations Benchmark\n";
print "=" x 60, "\n\n";

my @arr = 1..1000;
my $aref = \@arr;
my %hash = map { $_ => $_ * 2 } 1..1000;
my $href = \%hash;

bench/compose.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(compose);

print "=" x 60, "\n";
print "compose - Function Composition Benchmark\n";
print "=" x 60, "\n\n";

my $double = sub { $_[0] * 2 };
my $add_one = sub { $_[0] + 1 };
my $square = sub { $_[0] ** 2 };

bench/const.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';

use const qw/all/;
use Const::XS ();

print "=== const() scalar benchmark ===\n";
cmpthese(-2, {
    "const" => sub { const my $x => 42 },
    "Const::XS" => sub { Const::XS::const(my $y => 42) },
});
print "\n";

bench/count.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(count);

print "=" x 60, "\n";
print "count - Count Substring Occurrences Benchmark\n";
print "=" x 60, "\n\n";

my $str = "the quick brown fox jumps over the lazy dog the end the";
my $long_str = $str x 100;

# Pure Perl count using tr///

bench/defaults.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(defaults);

print "=" x 60, "\n";
print "defaults - Hash Defaults Benchmark\n";
print "=" x 60, "\n\n";

my $opts = { a => 1, b => undef };
my $defs = { a => 10, b => 20, c => 30 };

# Pure Perl defaults

bench/dig.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(dig);

print "=" x 60, "\n";
print "dig - Safe Hash Navigation Benchmark\n";
print "=" x 60, "\n\n";

my $data = {
    a => {
        b => {
            c => {

bench/final.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use List::Util ();
use util qw(final final_gt final_lt final_ge);

print "=" x 60, "\n";
print "final - Find Last Matching Element Benchmark\n";
print "=" x 60, "\n\n";

my @numbers = 1..1000;

# Pure Perl final using reverse

bench/first.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use List::Util ();
use util qw(first);

print "=" x 60, "\n";
print "first - Find First Matching Element Benchmark\n";
print "=" x 60, "\n\n";

my @numbers = 1..1000;

print "=== Match at position ~500 ===\n";

bench/first_cmp.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use List::Util ();
use util qw(first_gt first_lt first_ge first_le first_eq first_ne);

print "=" x 60, "\n";
print "first_* - Specialized First Comparison Benchmark\n";
print "=" x 60, "\n\n";

my @numbers = 1..1000;

print "=== first_gt vs List::Util::first (match ~500) ===\n";

bench/first_cmp_hash.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use List::Util ();
use util qw(first_gt first_ge first_lt);

print "=" x 60, "\n";
print "first_* (hash) - Array of Hashes Comparison Benchmark\n";
print "=" x 60, "\n\n";

my @users = map { { id => $_, age => 15 + int(rand(50)) } } 1..1000;
# Ensure some are adults and some are minors
$users[0]{age} = 17;

bench/hash_vs_object.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(:all);
use lib 'blib/lib', 'blib/arch';

use object;

# Define class in BEGIN so call checkers work
BEGIN {
    object::define('Thing', qw(key));
    object::import_accessors('Thing');
}

print "=" x 60, "\n";

bench/heap.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(:all);
use lib 'blib/lib', 'blib/arch';

use heap 'import';  # Import function-style API
use Array::Heap qw(make_heap push_heap pop_heap);

# Import raw array functions
*push_heap_min = \&heap::push_heap_min;
*pop_heap_min = \&heap::pop_heap_min;
*make_heap_min = \&heap::make_heap_min;

print "=" x 60, "\n";

bench/identity.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(identity);

print "=" x 60, "\n";
print "identity - Identity Function Benchmark\n";
print "=" x 60, "\n\n";

# Pure Perl identity
sub pure_identity { $_[0] }

my $value = 42;

bench/is_extended.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use Scalar::Util qw(blessed looks_like_number);
use util qw(is_num is_int is_blessed is_scalar_ref is_regex is_glob);

print "=" x 60, "\n";
print "Extended Type Predicates Benchmark\n";
print "=" x 60, "\n\n";

my $num = 42.5;
my $int = 42;
my $str = "hello";

bench/is_numeric.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(is_positive is_negative is_zero is_even is_odd is_between);

print "=" x 60, "\n";
print "Numeric Predicates Benchmark\n";
print "=" x 60, "\n\n";

my $pos = 42;
my $neg = -42;
my $zero = 0;
my $even = 100;

bench/is_string.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(is_empty starts_with ends_with contains);

print "=" x 60, "\n";
print "String Predicates Benchmark\n";
print "=" x 60, "\n\n";

my $str = "hello world";
my $empty = "";

print "=== is_empty (non-empty) ===\n";

bench/is_type.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(is_ref is_array is_hash is_code is_defined);

print "=" x 60, "\n";
print "is_* Type Predicates Benchmark\n";
print "=" x 60, "\n\n";

my $arrayref = [1, 2, 3];
my $hashref = { a => 1 };
my $coderef = sub { 1 };
my $scalar = 42;

bench/lazy.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(lazy force);

print "=" x 60, "\n";
print "lazy/force - Lazy Evaluation Benchmark\n";
print "=" x 60, "\n\n";

# Pure Perl lazy
sub pure_lazy {
    my $code = shift;
    my $forced = 0;

bench/lru2.pl  view on Meta::CPAN

#!/usr/bin/perl
use strict;
use warnings;
use lib 'blib/lib', 'blib/arch';
use lru qw(import);
use Time::HiRes qw(time);

my $cache = lru::new(10000);
my $iters = 5_000_000;

# Prefill
for (1..1000) { $cache->set("key$_", $_); }

# Benchmark lru_set function-style

bench/maybe.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(maybe);

print "=" x 60, "\n";
print "maybe - Conditional Return Benchmark\n";
print "=" x 60, "\n\n";

my $defined = 42;
my $undef = undef;
my $result = "result";

bench/memo.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use util qw(memo);

print "=" x 60, "\n";
print "memo - Memoization Benchmark\n";
print "=" x 60, "\n\n";

# Pure Perl memoization
sub pure_perl_memo {
    my $fn = shift;
    my %cache;

bench/minmax.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
use lib 'blib/lib', 'blib/arch';
use List::Util ();
use util qw(min2 max2);

print "=" x 60, "\n";
print "min2/max2 - Two-Value Min/Max Benchmark\n";
print "=" x 60, "\n\n";

my ($a, $b) = (42, 99);

print "=== min2 ===\n";



( run in 1.742 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )