|
my $timestamp = time ;
constant_time(
1 => sub {
my $j ;
for my $i ( 0 .. 1 ) {
$j += $i ;
}
}
);
my $delta = time - $timestamp ;
cmp_ok( $delta , '>' , 0.5, 'Constant time fixed at at least 0.5 second pass 1' );
cmp_ok( $delta , '<' , 1.5, 'Constant time fixed at at most 1.5 second pass 1' );
$timestamp = time ;
constant_time(
1 => sub {
my $j ;
for my $i ( 0 .. 50_000_000 ) {
$j += $i ;
}
}
);
$delta = time - $timestamp ;
cmp_ok( $delta , '>' , 0.5, 'Constant time fixed at at least 0.5 second pass 2' );
cmp_ok( $delta , '<' , 1.5, 'Constant time fixed at at most 1.5 second pass 2' );
done_testing;
|