File: advice.pl

package info (click to toggle)
libaspect-perl 1.04-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 720 kB
  • sloc: perl: 6,846; makefile: 2
file content (172 lines) | stat: -rw-r--r-- 4,057 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/perl

# Benchmark a variety of different Aspect use cases.
#
# Set 1 shows the main Aspect uses with Sub::Uplevel 0.22
#
# C:\cpan\trunk\Aspect>perl -Mblib benchmark\advice.pl
# Benchmark: timing 500000 iterations of after, after_returning, after_throwing, around, before, control, deep1, deep10, deep5...
#      after: 14 wallclock secs (12.76 usr +  0.00 sys = 12.76 CPU) @ 39181.88/s (n=500000)
# after_returning: 15 wallclock secs (13.56 usr +  0.02 sys = 13.57 CPU) @ 36840.55/s (n=500000)
# after_throwing: 14 wallclock secs (13.31 usr +  0.00 sys = 13.31 CPU) @ 37574.21/s (n=500000)
#     around: 26 wallclock secs (23.53 usr +  0.00 sys = 23.53 CPU) @ 21253.99/s (n=500000)
#     before:  4 wallclock secs ( 3.82 usr +  0.00 sys =  3.82 CPU) @ 130821.56/s (n=500000)
#    control:  0 wallclock secs ( 0.09 usr +  0.00 sys =  0.09 CPU) @ 5319148.94/s (n=500000)
#             (warning: too few iterations for a reliable count)
#      deep1: 40 wallclock secs (37.99 usr +  0.00 sys = 37.99 CPU) @ 13162.40/s (n=500000)
#     deep10: 26 wallclock secs (23.24 usr +  0.02 sys = 23.26 CPU) @ 21496.13/s (n=500000)
#      deep5: 34 wallclock secs (31.79 usr +  0.00 sys = 31.79 CPU) @ 15726.73/s (n=500000)
#
#
#
#
# Set 2 shows the main Aspect uses with the frame warning in Sub::Uplevel disabled
#
# C:\cpan\trunk\Aspect>perl -Mblib benchmark\advice.pl
# Benchmark: timing 500000 iterations of after, after_returning, after_throwing, around, before, control, deep1, deep10, deep5...
#      after:  5 wallclock secs ( 6.12 usr +  0.00 sys =  6.12 CPU) @ 81766.15/s (n=500000)
# after_returning:  7 wallclock secs ( 7.33 usr +  0.00 sys =  7.33 CPU) @ 68194.22/s (n=500000)
# after_throwing:  7 wallclock secs ( 6.33 usr +  0.00 sys =  6.33 CPU) @ 78951.52/s (n=500000)
#     around:  9 wallclock secs ( 9.13 usr +  0.00 sys =  9.13 CPU) @ 54788.52/s (n=500000)
#     before:  4 wallclock secs ( 3.87 usr +  0.00 sys =  3.87 CPU) @ 129232.36/s (n=500000)
#    control:  1 wallclock secs ( 0.08 usr +  0.00 sys =  0.08 CPU) @ 6410256.41/s (n=500000)
#             (warning: too few iterations for a reliable count)
#      deep1: 11 wallclock secs (10.72 usr +  0.00 sys = 10.72 CPU) @ 46650.49/s (n=500000)
#     deep10:  9 wallclock secs ( 9.14 usr +  0.00 sys =  9.14 CPU) @ 54698.61/s (n=500000)
#      deep5: 10 wallclock secs (10.27 usr +  0.00 sys = 10.27 CPU) @ 48709.21/s (n=500000)

use strict;
use Sub::Uplevel;
use Aspect;





######################################################################
# Test Class

SCOPE: {
	package Foo;

	sub control {
		return 1;
	}

	sub before {
		return 1;
	}

	sub after {
		return 1;
	}

	sub after_returning {
		return 1;
	}

	sub after_throwing {
		return 1;
	}

	sub around {
		return 1;
	}

	sub deep1 {
		deep2(@_);
	}

	sub deep2 {
		deep3(@_);
	}

	sub deep3 {
		deep4(@_);
	}

	sub deep4 {
		deep5(@_);
	}

	sub deep5 {
		deep6(@_);
	}

	sub deep6 {
		deep7(@_);
	}

	sub deep7 {
		deep8(@_);
	}

	sub deep8 {
		deep9(@_);
	}

	sub deep9 {
		deep10(@_);
	}

	sub deep10 {
		return 1;
	}
}





######################################################################
# Aspect Setup

my $foo = 1;

before {
	$foo++;
} call 'Foo::before';

after {
	$foo++;
} call 'Foo::after';

after {
	$foo++;
} call 'Foo::after_returning' & returning;

after {
	$foo++;
} call 'Foo::after_throwing' & throwing;

around {
	$foo++;
	$_->proceed
} call 'Foo::around';

around {
	$foo++;
	$_->proceed;
} call 'Foo::deep10';





######################################################################
# Benchmark Execution

use Benchmark qw{ :all :hireswallclock };

timethese( 100000, {
	control         => 'Foo::control()',
	before          => 'Foo::before()',
	after           => 'Foo::after()',
	after_returning => 'Foo::after_returning()',
	after_throwing  => 'Foo::after_throwing()',
	around          => 'Foo::around()',
	deep1           => 'Foo::deep1()',
	deep5           => 'Foo::deep5()',
	deep10          => 'Foo::deep10()',
	uplevel         => 'Sub::Uplevel::uplevel( 1, \&Foo::control )',
} );