Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 63 lines (51 sloc) 1.256 kB
8bcb39b added cpan/
moritz authored
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
bfb77ce [cpan] MEE
moritz authored
5 use lib 'lib';
8bcb39b added cpan/
moritz authored
6 use Carp qw(confess);
7 use Benchmark qw(cmpthese);
8 use Math::Expression::Evaluator;
9 use Data::Dumper;
10
bfb77ce [cpan] MEE
moritz authored
11 my $statement = '2 + a + 5 + (3+4)';
8c0610e [cpan] MEE: many updates, nearly version 0.0.6 now
moritz authored
12 my $iterations = $ARGV[0] || 200;
8bcb39b added cpan/
moritz authored
13
14 sub with_optimize {
15 my $m = Math::Expression::Evaluator->new($statement);
16 $m->optimize;
8c0610e [cpan] MEE: many updates, nearly version 0.0.6 now
moritz authored
17 for (1..$iterations){
8bcb39b added cpan/
moritz authored
18 $m->val({a => $_});
19 }
20 }
21
22 sub no_optimize {
23 my $m = Math::Expression::Evaluator->new($statement);
8c0610e [cpan] MEE: many updates, nearly version 0.0.6 now
moritz authored
24 for (1..$iterations){
8bcb39b added cpan/
moritz authored
25 $m->val({a => $_});
26 }
27 }
28
8c0610e [cpan] MEE: many updates, nearly version 0.0.6 now
moritz authored
29 sub compiled {
30 my $m = Math::Expression::Evaluator->new($statement);
31 my $c = $m->compiled();
32 for (1..$iterations){
33 $c->({a => $_});
34 }
35 }
36
37 sub opt_compiled {
38 my $m = Math::Expression::Evaluator->new($statement);
39 $m->optimize();
40 my $c = $m->compiled();
41 for (1..$iterations){
42 $c->({a => $_});
43 }
44 }
45
46
8bcb39b added cpan/
moritz authored
47 my %tests = (
8c0610e [cpan] MEE: many updates, nearly version 0.0.6 now
moritz authored
48 optimize => \&with_optimize,
49 no_optimize => \&no_optimize,
50 compiled => \&compiled,
51 opt_compiled => \&opt_compiled,
8bcb39b added cpan/
moritz authored
52 );
53 #for (100,1000,10000){
54 # print $_, "\n";
55 # $tests{'opt ' . $_} = sub { with_optimize($_) };
56 # $tests{'noopt ' . $_} = sub { no_optimize($_) };
57 #}
58
59 cmpthese(-2, \%tests);
60
61
62 # vim: expandtab
Something went wrong with that request. Please try again.