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
|
# ========================================================================
# t/01_basic.t - ensure that Benchmark::Timer object can be created, used
# Andrew Ho (andrew@zeuscat.com)
#
# Test basic usage of the Benchmark::Timer library.
#
# Because timings will differ from system to system, we can't actually
# test the functionality of the module. So we just test that all the
# method calls run without triggering exceptions.
#
# This script is intended to be run as a target of Test::Harness.
#
# Last modified April 20, 2001
# ========================================================================
use strict;
use Test::More tests => 11;
use Time::HiRes;
# 1
BEGIN { use_ok( 'Benchmark::Timer') }
# ------------------------------------------------------------------------
# Basic tests of the Benchmark::Timer library.
my $t = Benchmark::Timer->new;
#2
ok(defined $t, 'Construct Benchmark::Timer');
$t->reset;
#3
ok(1, 'reset');
my $before = [ Time::HiRes::gettimeofday ]; # minimize overhead
$t->start('tag');
while (Time::HiRes::tv_interval($before, [Time::HiRes::gettimeofday]) == 0) {
Time::HiRes::usleep(10);
}
$t->stop;
#4
ok(1, 'Start/stop a tag');
my $result = $t->result('tag');
#5
isnt($result, 0, 'Nonzero single result');
my @results = $t->results;
#6
is(scalar @results, 2, 'Multiple results');
my $results = $t->results;
#7
isa_ok($results, 'ARRAY', 'Array ref results');
my @data = $t->data('tag');
#8
is(scalar @data, 1, 'tag data array');
my $data = $t->data('tag');
#9
isa_ok($data, 'ARRAY', 'Array ref data');
@data = $t->data;
#10
is(scalar @data, 2, 'all tags data array');
$data = $t->data;
#11
isa_ok($data, 'ARRAY', 'all tags data ref');
# ========================================================================
__END__
|