Convert-Binary-C
view release on metacpan or search on metacpan
tests/601_speed.t view on Meta::CPAN
################################################################################
#
# Copyright (c) 2002-2024 Marcus Holland-Moritz. All rights reserved.
# This program is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
#
################################################################################
use Test;
use Convert::Binary::C @ARGV;
use Convert::Binary::C::Cached;
$^W = 1;
BEGIN {
plan tests => 11;
}
my $CCCFG = require './tests/include/config.pl';
push @{$CCCFG->{Define}}, 'CACHE_TEST=1';
push @{$CCCFG->{Include}}, 'tests/include';
eval { require Data::Dumper }; $Data_Dumper = $@;
eval { require IO::File }; $IO_File = $@;
if( $Data_Dumper or $IO_File ) {
my $req;
$req = 'IO::File' if $IO_File;
$req = 'Data::Dumper' if $Data_Dumper;
$req = 'Data::Dumper and IO::File' if $Data_Dumper && $IO_File;
skip( "caching requires $req", 0 ) for 1 .. 11;
exit;
}
else { ok(1) }
eval { my @dummy = times };
if( $@ ) {
print "# no times() funtion, trying Time::HiRes...\n";
eval {
require Time::HiRes;
*main::mytime = \&Time::HiRes::time;
$required_time = 5;
$time_per_test = 1;
};
if( $@ ) {
print "# can't load Time::HiRes, using time()...\n";
*main::mytime = sub { time };
$required_time = 20;
$time_per_test = 4;
}
}
else {
print "# using times() for timing...\n";
*main::mytime = sub { my @t = times; $t[0]+$t[1] };
$required_time = 5;
$time_per_test = 1;
}
$cache = 'tests/cache.cbc';
-e $cache and unlink $cache;
# check "normal" C::B::C object
$tests = 5;
$next_test_time = 0;
$iterations = 0;
$start_time = mytime();
$elapsed_time = 0;
$fail = 0;
while ($elapsed_time < $required_time) {
eval {
$c = Convert::Binary::C->new( %$CCCFG );
$c->parse_file( 'tests/include/include.c' );
};
$@ and $fail = 1 and last;
$iterations++;
$elapsed_time = mytime() - $start_time;
( run in 1.391 second using v1.01-cache-2.11-cpan-39bf76dae61 )