blib/lib/Benchmark/Perl/Formance/Plugin/ThreadsShared.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.6% 13 / 15 CC 1 SCAR 0.7
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/Benchmark/Perl/Formance/Plugin/Threads.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/AccessorsClassMethodMaker.pm »
1 package Benchmark::Perl::Formance::Plugin::ThreadsShared;
2 our $AUTHORITY = 'cpan:SCHWIGON';
3 # ABSTRACT: benchmark plugin - ThreadsShared - Stress shared threading
4  
5 # Create threads to evaluate Fibonacci numbers
6  
7 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 our $VERSION = "0.002";
12  
13 #############################################################
14 # #
15 # Benchmark Code ahead - Don't touch without strong reason! #
16 # #
17 #############################################################
18  
19 our $goal;
20 our $count;
21 our $threadcount;
22 our $val;
23 our $expect1;
24  
25 0 ▶use threads;
Subroutine BEGIN: called CC=1 SCAR=2.6
26 use threads::shared;
27  
28 use Benchmark ':hireswallclock';
29 use Data::Dumper;
30  
31 my @result : shared;
32 $#result = 1_000;
33  
34 my $size;
35 eval qq{use Devel::Size 'total_size'};
36 if ($@) {
37 $size = "error-no-Devel-Size-available";
38 } else {
39 $size = total_size(\@result);
40 }
41  
42 sub run_thread_storm_shared
43 {
44 my ($options) = @_;
45  
46 $result[-1] = 0;
47 my @t;
48 foreach (1..$threadcount) {
49 push @t, async {
50 # print STDERR ".";
51 $result[-1] += $val;
52 }
53 }
54 foreach (@t) {
55 $_->join;
56 }
57  
58 return $result[-1];
59 }
60  
61 sub threadstorm
62 {
63 my ($options) = @_;
64  
65 $goal = $options->{fastmode} ? 3 : 25;
66 $threadcount = $options->{fastmode} ? 5 : ($options->{D}{Threads_threadcount} || 100);
67 $val = 25;
68 $expect1 = $threadcount * $val;
69  
70 my $ret1;
71 my $t1 = timeit($goal, sub { $ret1 = run_thread_storm_shared ($options) });
72  
73 return {
74 Benchmark => $t1,
75 threadcount => $threadcount,
76 total_size => $size,
77 result => $ret1,
78 expect => $expect1,
79 useforks => ($options->{useforks} || 0),
80 };
81 }
82  
83 sub main
84 {
85 my ($options) = @_;
86  
87 return {
88 threadstorm => threadstorm($options),
89 };
90 }
91  
92 1;
93  
94 __END__
« blib/lib/Benchmark/Perl/Formance/Plugin/Threads.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/AccessorsClassMethodMaker.pm »