bench/run-resolver-microbench.pl

filter: Statementstmt 44.6% 29 / 65 Branchbran 12.5% 2 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 8 / 12 Podpod n/a totaltotal 39.8% 39 / 98 CC 4 SCAR 13.9
CC
4
Cov
37%
_resolver_completed
12.0
median
6.0
new
2.0
CRAP 4.0
« blib/lib/Linux/Event/IO/Sock/Listener.pm ↑ Summary bench/run-timer-microbench.pl »
1 #!/usr/bin/env perl
2 1 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Getopt::Long qw(GetOptions);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Linux::Event::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Linux::Event::_Resolver ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 my $requests = 1_000;
13 1 my $repeats = 5;
14 1 my $host = 'localhost';
15 1 my $service = 80;
16 1 my $help;
17  
18 1 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("requests=i", \$requests, "repeats=i", \$repeats, "host=s", \$host, "service=i", \$service, "help", \$help) or usage(1) 1 0 1
19 'requests=i' => \$requests,
20 'repeats=i' => \$repeats,
21 'host=s' => \$host,
22 'service=i' => \$service,
23 'help' => \$help,
24 ) or usage(1);
25 1 ▶usage(0) if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 1 0 1
26 0 ▶die "requests must be positive\n" if $requests < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $requests < 1 0 0 0
27 0 ▶die "repeats must be positive\n" if $repeats < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $repeats < 1 0 0 0
28 0 ▶die "service must be between 0 and 65535\n"
Branch: 1 branch
BranchTrueFalseTotal
if $service < 0 or $service > 65535 0 0 0
Condition0%0/3
$service < 0 or $service > 65535
l!l&&r!l&&!r
000
MC/DC0%0/2
$service < 0 or $service > 65535
$service < 0 $service > 65535
Truth table0%0/3
A or B
A= $service < 0B= $service > 65535
ABresult
1X1
011
000
29 if $service < 0 || $service > 65_535;
30  
31 {
32 package BenchResolverTarget;
33 0 ▶ sub new ($class, $run) { bless { run => $run }, $class }
Subroutine new: not called CC=1 SCAR=6.9
34 0 ▶ sub _resolver_completed ($self, $result) {
Subroutine _resolver_completed: not called CC=3 SCAR=24.8
35 0 my $run = $self->{run};
36 die "resolver benchmark failed: $result->{message}\n"
37 0 ▶ if $result->{error_code};
Branch: 1 branch
BranchTrueFalseTotal
if $result->{"error_code"} 0 0 0
38 0 my $started = delete $run->{started}{ $result->{id} };
39 0 push @{ $run->{latencies} }, main::now() - $started;
40 0 $run->{completed}++;
41 0 ▶ $run->{loop}->stop if $run->{completed} == $run->{requests};
Branch: 1 branch
BranchTrueFalseTotal
if $run->{"completed"} == $run->{"requests"} 0 0 0
42 }
43 }
44  
45 0 ▶sub now () { clock_gettime(CLOCK_MONOTONIC) }
Subroutine now: not called CC=1 SCAR=6.9
46  
47 0 ▶sub median (@values) {
Subroutine median: not called CC=2 SCAR=17.9
48 0 @values = sort { $a <=> $b } @values;
49 0 my $middle = int(@values / 2);
50 0 ▶ return @values % 2
Branch: 1 branch
BranchTrueFalseTotal
@values % 2 ? : 0 0 0
51 ? $values[$middle]
52 : ($values[$middle - 1] + $values[$middle]) / 2;
53 }
54  
55 0 my (@rates, @latencies);
56 0 for (1 .. $repeats) {
57 0 my $loop = Linux::Event::Loop->new;
58 0 my $resolver = Linux::Event::_Resolver->for_loop($loop);
59 0 my $run = {
60 loop => $loop, requests => $requests, completed => 0,
61 started => {}, latencies => [],
62 };
63 0 my $target = BenchResolverTarget->new($run);
64 0 my $batch_start = now();
65 0 for (1 .. $requests) {
66 0 my $submitted = now();
67 0 my $id = $resolver->submit($target, $host, $service);
68 0 $run->{started}{$id} = $submitted;
69 }
70 0 $loop->run;
71 0 my $elapsed = now() - $batch_start;
72 0 push @rates, $requests / $elapsed;
73 0 push @latencies, @{ $run->{latencies} };
74 }
75  
76 0 printf "resolver host=%s requests=%d repeats=%d\n", $host, $requests, $repeats;
77 0 printf "median rate: %.0f resolutions/s\n", median(@rates);
78 0 printf "median completion latency: %.3f ms\n", median(@latencies) * 1_000;
79  
80 1 ▶sub usage ($exit) {
Subroutine usage: called CC=1 SCAR=0.0
81 1 print <<'USAGE';
82 Usage: run-resolver-microbench.pl [options]
83 --requests=N resolutions per repeat (default: 1000)
84 --repeats=N measured repeats (default: 5)
85 --host=NAME hostname to resolve (default: localhost)
86 --service=PORT numeric service (default: 80)
87 --help show this help
88 USAGE
89 1 exit $exit;
90 }
« blib/lib/Linux/Event/IO/Sock/Listener.pm ↑ Summary bench/run-timer-microbench.pl »