]> git.vpit.fr Git - perl/modules/Test-Leaner.git/blob - samples/bench.pl
Better benchmark
[perl/modules/Test-Leaner.git] / samples / bench.pl
1 #!perl
2
3 use strict;
4 use warnings;
5
6 my $n1    = 1000;
7 my $n2    = 100;
8 my $tests = 10_000;
9
10 use File::Spec;
11 use Benchmark qw<cmpthese :hireswallclock>;
12
13 my $has_test_tiny;
14 BEGIN {
15  $has_test_tiny = do {
16   local $@;
17   eval { require Test::Tiny; 1 }
18  }
19 }
20
21 my $dev_null = File::Spec->devnull;
22
23 my %test_modules = (
24  'Test::More'   => sub { system "$^X -e 'use Test::More tests => 1; ok(1);' > $dev_null" },
25  'Test::Leaner' => sub { system "$^X -Ilib -e 'use Test::Leaner tests => 1; ok(1);' > $dev_null" },
26 );
27
28 if ($has_test_tiny) {
29  $test_modules{'Test::Tiny'} = sub { system "$^X -e 'use Test::Tiny tests => 1; ok(1);' > $dev_null" },
30 }
31
32 print "Loading:\n";
33 cmpthese $n1, \%test_modules;
34 print "\n";
35
36 require Test::More;
37 require Test::Builder;
38 require Test::Leaner;
39
40 open my $nullfh, '>', $dev_null or die "Can't open null fh: $!";
41
42 Test::Builder->new->output($nullfh);
43 Test::Leaner::tap_stream($nullfh);
44
45 Test::More::plan('no_plan');
46 Test::Leaner::plan('no_plan');
47
48 %test_modules = (
49  'Test::More'    => sub { Test::More::ok(1)   for 1 .. $tests },
50  'Test::Leaner'  => sub { Test::Leaner::ok(1) for 1 .. $tests },
51 );
52
53 if ($has_test_tiny) {
54  $test_modules{'Test::Tiny'} = sub { my $outfh = select $nullfh; Test::Tiny::ok(1) for 1 .. $tests; select $outfh },
55 }
56
57 print "Simple tests:\n";
58 cmpthese $n2, \%test_modules;