« blib/lib/Benchmark/Perl/Formance/Plugin/Shootout/mandelbrot.pm
↑ Summary
blib/lib/Benchmark/Perl/Formance/Plugin/ThreadsShared.pm »
| 1 | package Benchmark::Perl::Formance::Plugin::Threads; | ||
| 2 | our $AUTHORITY = 'cpan:SCHWIGON'; | ||
| 3 | # ABSTRACT: benchmark plugin - Threads - Stress 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.001"; | ||
| 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 $expect2; | ||
| 24 | |||
| 25 | 0 | ▶ | use threads; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 26 | |||
| 27 | my $result; | ||
| 28 | |||
| 29 | use Benchmark ':hireswallclock'; | ||
| 30 | use Data::Dumper; | ||
| 31 | |||
| 32 | sub run_thread_storm_noshared | ||
| 33 | { | ||
| 34 | my ($options) = @_; | ||
| 35 | |||
| 36 | my @t; | ||
| 37 | foreach (1..$threadcount) { | ||
| 38 | push @t, async { | ||
| 39 | # print STDERR "."; | ||
| 40 | 1; # no-op | ||
| 41 | } | ||
| 42 | } | ||
| 43 | foreach (@t) { | ||
| 44 | $_->join; | ||
| 45 | } | ||
| 46 | |||
| 47 | return scalar @t; | ||
| 48 | } | ||
| 49 | |||
| 50 | sub threadstorm | ||
| 51 | { | ||
| 52 | my ($options) = @_; | ||
| 53 | |||
| 54 | $goal = $options->{fastmode} ? 3 : 25; | ||
| 55 | $threadcount = $options->{fastmode} ? 5 : ($options->{D}{Threads_threadcount} || 100); | ||
| 56 | $val = 25; | ||
| 57 | $expect2 = $threadcount; | ||
| 58 | |||
| 59 | my $ret2; | ||
| 60 | my $t2 = timeit($goal, sub { $ret2 = run_thread_storm_noshared($options) }); | ||
| 61 | |||
| 62 | return { | ||
| 63 | Benchmark => $t2, | ||
| 64 | threadcount => $threadcount, | ||
| 65 | result => $ret2, | ||
| 66 | expect => $expect2, | ||
| 67 | useforks => ($options->{useforks} || 0), | ||
| 68 | }; | ||
| 69 | } | ||
| 70 | |||
| 71 | sub main | ||
| 72 | { | ||
| 73 | my ($options) = @_; | ||
| 74 | |||
| 75 | return { | ||
| 76 | threadstorm => threadstorm($options), | ||
| 77 | }; | ||
| 78 | } | ||
| 79 | |||
| 80 | 1; | ||
| 81 | |||
| 82 | __END__ | ||