File: bench.pl

package info (click to toggle)
libsub-recursive-perl 0.05-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 120 kB
  • sloc: perl: 60; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,122 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl

use strict;
use warnings;
use Benchmark qw(cmpthese);

use Sub::Recursive;

use vars qw/ $rec /;

sub manual_recursive {
    my $_foo = sub { @_ ? $_[0] + $rec->(@_[1 .. $#_]) : 0 };
    return sub {
        local $rec = $_foo;
        $_foo->(@_);
    };
}

sub leaker {
    my $_foo;
    $_foo = sub { @_ ? $_[0] + $_foo->(@_[1 .. $#_]) : 0 };
    return $_foo;
}

my $leaker = leaker();
my $manual = manual_recursive();
my $recursive = recursive { @_ ? $_[0] + $REC->(@_[1 .. $#_]) : 0 };

my @vals = 1 .. 50;

cmpthese(-10, {
    leaker => sub { $leaker->(@vals) },
    manual => sub { $manual->(@vals) },
    recursive => sub { $recursive->(@vals) },
});

__END__
            Rate    manual recursive    leaker
recursive 1447/s        --       -0%       -0%
manual    1449/s        0%        --       -0%
leaker    1454/s        0%        0%        --


This is perl, v5.8.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2002, Larry Wall

Binary build 806 provided by ActiveState Corp. http://www.ActiveState.com
Built 00:45:44 Mar 31 2003