[Templates-cvs] cvs commit: TT3/benchmark passargs.pl
cvs@template-toolkit.org
cvs@template-toolkit.org
Fri, 19 Dec 2003 12:54:01 +0000
cvs 03/12/19 12:54:00
Modified: benchmark passargs.pl
Log:
* added new test for passing hash
Revision Changes Path
1.2 +41 -19 TT3/benchmark/passargs.pl
Index: passargs.pl
===================================================================
RCS file: /template-toolkit/TT3/benchmark/passargs.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- passargs.pl 2003/12/19 12:08:03 1.1
+++ passargs.pl 2003/12/19 12:54:00 1.2
@@ -33,15 +33,20 @@
# $foo->c($c);
# $foo->bar();
#
-# Benchmark: timing 500000 iterations of pass_args, pre_glob, pre_method, pre_set...
-# pass_args: 5 wallclock secs ( 2.78 usr + 0.02 sys = 2.80 CPU)
-# @ 178571.43/s (n=500000)
-# pre_set: 4 wallclock secs ( 2.26 usr + 0.01 sys = 2.27 CPU)
-# @ 220264.32/s (n=500000)
-# pre_glob: 8 wallclock secs ( 3.19 usr + 0.02 sys = 3.21 CPU)
-# @ 155763.24/s (n=500000)
-# pre_method: 16 wallclock secs ( 7.44 usr + 0.03 sys = 7.47 CPU)
-# @ 66934.40/s (n=500000)
+# Benchmark: timing 500000 iterations of pass_args, pass_hash, pass_set,
+# pre_glob, pre_method, pre_set...
+# pass_args: 3 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU)
+# @ 476190.48/s (n=500000)
+# pass_hash: 6 wallclock secs ( 2.76 usr + -0.00 sys = 2.76 CPU)
+# @ 181159.42/s (n=500000)
+# pass_set: 4 wallclock secs ( 1.98 usr + 0.01 sys = 1.99 CPU)
+# @ 251256.28/s (n=500000)
+# pre_glob: 5 wallclock secs ( 2.09 usr + 0.02 sys = 2.11 CPU)
+# @ 236966.82/s (n=500000)
+# pre_method: 11 wallclock secs ( 5.11 usr + 0.02 sys = 5.13 CPU)
+# @ 97465.89/s (n=500000)
+# pre_set: 3 wallclock secs ( 1.53 usr + 0.00 sys = 1.53 CPU)
+# @ 326797.39/s (n=500000)
#
use strict;
@@ -52,15 +57,19 @@
use Class::Base;
use base qw( Class::Base );
-sub bar {
+sub none {
my $self = shift;
- if ($main::DEBUG) {
- print "bar line: $self->{ line }\n";
- print "bar size: $self->{ size }\n";
- }
+}
+
+sub one {
+ my ($self, $hash) = @_;
+}
+
+sub four {
+ my ($self, $line, $size, $blim, $blam) = @_;
}
-sub baz {
+sub setfour {
my ($self, $line, $size, $blim, $blam) = @_;
$self->{ line } = $line;
$self->{ size } = $size;
@@ -92,6 +101,8 @@
return @_ ? ($self->{ blam } = shift) : $self->{ blam };
}
+#------------------------------------------------------------------------
+
package main;
use Benchmark;
@@ -102,7 +113,7 @@
$foo->{ size } = 20;
$foo->{ blim } = 30;
$foo->{ blam } = 40;
- $foo->bar();
+ $foo->none();
}
sub pre_method {
@@ -110,21 +121,32 @@
$foo->size(20);
$foo->blim(30);
$foo->blam(40);
- $foo->bar();
+ $foo->none();
}
sub pre_glob {
@$foo{ qw( line size blim blam ) } = (10, 20, 30, 40);
- $foo->bar();
+ $foo->none();
}
sub pass_args {
- $foo->baz(30, 40, 50, 60);
+ $foo->four(30, 40, 50, 60);
+}
+
+sub pass_set {
+ $foo->setfour(30, 40, 50, 60);
+}
+
+sub pass_hash {
+ $foo->one({ a => 30, b => 40, c => 50, d => 60 });
}
+#------------------------------------------------------------------------
timethese($DEBUG ? 1 : 500_000, {
pass_args => \&pass_args,
+ pass_hash => \&pass_hash,
+ pass_set => \&pass_set,
pre_set => \&pre_set,
pre_glob => \&pre_glob,
pre_method => \&pre_method,