line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Benchmark::Perl::Formance::Plugin::Mandelbrot::withmce; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:SCHWIGON'; |
3
|
|
|
|
|
|
|
# ABSTRACT: benchmark - Generate Mandelbrot set portable bitmap file - using MCE |
4
|
|
|
|
|
|
|
$Benchmark::Perl::Formance::Plugin::Mandelbrot::withmce::VERSION = '0.001'; |
5
|
|
|
|
|
|
|
# http://www.perlmonks.org/?node_id=1129370 |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# http://benchmarksgame.alioth.debian.org/u64q/performance.php?test=mandelbrot |
8
|
|
|
|
|
|
|
# based on Perl code contributed by Mykola Zubach |
9
|
|
|
|
|
|
|
# parallelization via MCE by Mario Roy |
10
|
|
|
|
|
|
|
|
11
|
9
|
|
|
9
|
|
36
|
use strict; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
225
|
|
12
|
9
|
|
|
9
|
|
27
|
use warnings; |
|
9
|
|
|
|
|
9
|
|
|
9
|
|
|
|
|
243
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
############################################################# |
15
|
|
|
|
|
|
|
# # |
16
|
|
|
|
|
|
|
# Benchmark Code ahead - Don't touch without strong reason! # |
17
|
|
|
|
|
|
|
# # |
18
|
|
|
|
|
|
|
############################################################# |
19
|
|
|
|
|
|
|
|
20
|
9
|
|
|
9
|
|
4698
|
use Benchmark ':hireswallclock'; |
|
9
|
|
|
|
|
39681
|
|
|
9
|
|
|
|
|
36
|
|
21
|
|
|
|
|
|
|
|
22
|
9
|
|
|
9
|
|
4905
|
use MCE::Flow; |
|
9
|
|
|
|
|
80694
|
|
|
9
|
|
|
|
|
45
|
|
23
|
|
|
|
|
|
|
|
24
|
9
|
|
|
9
|
|
223443
|
use constant MAXITER => 50; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
504
|
|
25
|
9
|
|
|
9
|
|
27
|
use constant LIMIT => 4.0; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
351
|
|
26
|
9
|
|
|
9
|
|
27
|
use constant XMIN => -1.5; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
315
|
|
27
|
9
|
|
|
9
|
|
27
|
use constant YMIN => -1.0; |
|
9
|
|
|
|
|
9
|
|
|
9
|
|
|
|
|
351
|
|
28
|
9
|
|
|
9
|
|
27
|
use constant WHITE => "\000"; |
|
9
|
|
|
|
|
9
|
|
|
9
|
|
|
|
|
405
|
|
29
|
9
|
|
|
9
|
|
27
|
use constant BLACK => "\001"; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
2511
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my ( $w, $h, $m, $invN ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub draw_line { |
34
|
201
|
|
|
201
|
0
|
134541
|
my ( $mce, $y, $chunk_id ) = @_; |
35
|
201
|
|
|
|
|
242
|
my ( $Cr, $Zr, $Zi, $Tr, $Ti ); |
36
|
201
|
|
|
|
|
385
|
my $Ci = $y * $invN + YMIN; |
37
|
201
|
|
|
|
|
235
|
my $line; |
38
|
|
|
|
|
|
|
|
39
|
201
|
|
|
|
|
470
|
LOOP: for my $x (0 .. $w - 1) { |
40
|
80400
|
|
|
|
|
59359
|
$Cr = $x * $invN + XMIN; |
41
|
80400
|
|
|
|
|
73406
|
$Zr = $Zi = $Tr = $Ti = 0.0; |
42
|
|
|
|
|
|
|
|
43
|
80400
|
|
|
|
|
80835
|
for (1 .. MAXITER) { |
44
|
1962446
|
|
|
|
|
1335531
|
$Zi = $Zi * 2 * $Zr + $Ci; |
45
|
1962446
|
|
|
|
|
1216203
|
$Zr = $Tr - $Ti + $Cr; |
46
|
1962446
|
|
|
|
|
1223610
|
$Ti = $Zi * $Zi; |
47
|
1962446
|
|
|
|
|
1156193
|
$Tr = $Zr * $Zr; |
48
|
1962446
|
100
|
|
|
|
2519676
|
if ($Tr + $Ti > LIMIT) { |
49
|
48460
|
|
|
|
|
36529
|
$line .= WHITE; |
50
|
48460
|
|
|
|
|
48777
|
next LOOP; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
31940
|
|
|
|
|
28553
|
$line .= BLACK; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
201
|
|
|
|
|
3215
|
MCE->gather( $chunk_id, pack('B*', $line) ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
## MAIN() |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub run |
63
|
|
|
|
|
|
|
{ |
64
|
9
|
|
|
9
|
0
|
18
|
$w = $h = shift; |
65
|
9
|
|
|
|
|
18
|
$m = int( $h / 2 ); |
66
|
9
|
|
|
|
|
18
|
$invN = 2 / $w; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Compute upper-half only, gather lines |
69
|
|
|
|
|
|
|
|
70
|
9
|
|
|
|
|
81
|
my %picture = mce_flow_s { chunk_size => 1 }, \&draw_line, 0, $m; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Output PBM image header |
73
|
|
|
|
|
|
|
# Output upper half |
74
|
|
|
|
|
|
|
# Remove first and last lines |
75
|
|
|
|
|
|
|
# Output bottom half in reverse |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
2413214
|
binmode STDOUT; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub main |
81
|
|
|
|
|
|
|
{ |
82
|
9
|
|
|
9
|
0
|
9
|
my ($options) = @_; |
83
|
|
|
|
|
|
|
|
84
|
9
|
50
|
|
|
|
27
|
my $goal = $options->{fastmode} ? 400 : 2_000; |
85
|
9
|
50
|
|
|
|
9
|
my $count = $options->{fastmode} ? 1 : 5; |
86
|
|
|
|
|
|
|
|
87
|
9
|
|
|
|
|
18
|
my $result; |
88
|
9
|
|
|
9
|
|
72
|
my $t = timeit $count, sub { $result = run($goal) }; |
|
9
|
|
|
|
|
139869
|
|
89
|
|
|
|
|
|
|
return { |
90
|
1
|
|
|
|
|
192
|
Benchmark => $t, |
91
|
|
|
|
|
|
|
goal => $goal, |
92
|
|
|
|
|
|
|
count => $count, |
93
|
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |