File: class-std.pl

package info (click to toggle)
libclass-std-fast-perl 0.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 216 kB
  • sloc: perl: 575; makefile: 2
file content (78 lines) | stat: -rw-r--r-- 2,026 bytes parent folder | download | duplicates (4)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use lib '../lib';
use Benchmark;
my @list;

package MyBenchTestFastBasic;
use Class::Std::Fast constructor => 'basic', isa_unsorted => 1;

my %one_of :ATTR(:name<one> :default<()>);
my %two_of :ATTR(:name<two> :default<()>);
my %three_of :ATTR(:name<three> :default<()>);
my %four_of :ATTR(:name<four> :default<()>);

Class::Std::initialize;

1;

package MyBenchTestFast;
use Class::Std::Fast;

my %one_of :ATTR(:name<one> :default<()>);
my %two_of :ATTR(:name<two> :default<()>);
my %three_of :ATTR(:name<three> :default<()>);
my %four_of :ATTR(:name<four> :default<()>);

Class::Std::initialize;

1;

package MyBenchTest;
use Class::Std;

my %one_of :ATTR(:name<one> :default<()>);
my %two_of :ATTR(:name<two> :default<()>);
my %three_of :ATTR(:name<three> :default<()>);
my %four_of :ATTR(:name<four> :default<()>);

Class::Std::initialize;
1;

package MyBenchTestFastCache;
use Class::Std::Fast constructor => 'basic', cache => 1 , isa_unsorted => 1;

my %one_of :ATTR(:name<one>);
my %two_of :ATTR(:name<two>);
my %three_of :ATTR(:name<three>);
my %four_of :ATTR(:name<four>);
Class::Std::initialize;
1;


package main;
print "Info:
Each test creates an object an stacks two objects into it (two levels)\n";

for my $class ('MyBenchTestFastCache', 'MyBenchTestFastBasic') {
    #, 'MyBenchTestFast', 'MyBenchTest') {
    my $n = 100000;
    print "\n$class ($n iterations - first run)\n";
    timethis $n, sub {
        push @list,  $class->new();
        $list[-1]->set_one($class->new());
        $list[-1]->get_one()->set_two($class->new());
        $list[-1]->get_one();
    };
    print "Cleanup: Destroying ${ \($n *3) } objects\n";
    timethis 1, sub { undef @list };
    print "\n$class ($n iterations - second run)\n";
    timethis $n , sub {
        push @list,  $class->new();
        $list[-1]->set_one($class->new());
        $list[-1]->get_one()->set_two($class->new());
        $list[-1]->get_one();
    };
    print "Cleanup: Destroying ${ \($n *3) } objects\n";
    timethis 1, sub { undef @list };
}