Algorithm-EventsPerSecond

 view release on metacpan or  search on metacpan

benchmark.pl  view on Meta::CPAN

	'time=f'    => \$time,
	'windows=s' => \$windows,
	'help'      => sub { print "usage: $0 [--time seconds] [--windows csv]\n"; exit 0 },
) or die "usage: $0 [--time seconds] [--windows csv]\n";

my @windows = grep { /^\d+$/ && $_ > 0 } split /,/, $windows;
die "no valid window sizes in --windows\n" unless @windows;

#
# child mode: benchmark whatever backend loads and emit tab-separated
# "label \t ops-per-second" lines for the parent to collate
#
if ( $ENV{AEPS_BENCH_CHILD} ) {
	require Algorithm::EventsPerSecond;
	require Benchmark;

	my $backend = Algorithm::EventsPerSecond->backend;
	my $simd    = Algorithm::EventsPerSecond->simd;
	print "BACKEND\t", ( defined $simd ? "$backend ($simd)" : $backend ), "\n";

	my $bench = sub {

benchmark.pl  view on Meta::CPAN


		# a realistic consumer: record events, check the rate every 100
		my $i = 0;
		$bench->( "mark + rate/100, window=$w", 1, sub { $m->mark; $m->rate if ++$i % 100 == 0; } );
	} ## end for my $w (@windows)

	exit 0;
} ## end if ( $ENV{AEPS_BENCH_CHILD} )

#
# parent mode: run one child per backend and print a comparison
#
sub run_child {
	my %env = ( @_, AEPS_BENCH_CHILD => 1 );
	local @ENV{ keys %env } = values %env;

	my @cmd = ( $^X, ( map { "-I$_" } @incs ), $0, '--time', $time, '--windows', join( ',', @windows ), );
	open my $fh, '-|', @cmd or die "cannot run child benchmark: $!\n";

	my ( $backend, %rate, @order );
	while ( my $line = <$fh> ) {

t/lib/Sukkal_TestUtil.pm  view on Meta::CPAN

sub spawn_daemon {
	my (%args) = @_;

	my $dir  = tempdir( CLEANUP => 1 );
	my $path = delete $args{socket} // "$dir/sukkal.sock";

	my $pid = fork;
	die "fork failed: $!" unless defined $pid;

	if ( $pid == 0 ) {
		# _exit so the parent's Test::More END block does not run twice
		my $ok = eval {
			my $d = Algorithm::EventsPerSecond::Sukkal->new( socket => $path, %args );
			$SIG{TERM} = sub { $d->stop };
			$d->run;
			1;
		};
		warn $@ if !$ok;
		POSIX::_exit( $ok ? 0 : 1 );
	} ## end if ( $pid == 0 )

t/sukkal.t  view on Meta::CPAN

use Time::HiRes qw(sleep);
use Algorithm::EventsPerSecond::Sukkal;

my $dir  = tempdir( CLEANUP => 1 );
my $path = "$dir/sukkal.sock";

my $pid = fork;
die "fork failed: $!" unless defined $pid;

if ( $pid == 0 ) {
	# daemon child; _exit so the parent's Test::More END block does
	# not run twice
	my $ok = eval {
		my $d = Algorithm::EventsPerSecond::Sukkal->new(
			socket   => $path,
			window   => 5,
			max_keys => 4,
		);
		$SIG{TERM} = sub { $d->stop };
		$d->run;
		1;



( run in 1.307 second using v1.01-cache-2.11-cpan-995e09ba956 )