source code
# The Computer Language Benchmarks Game
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
#
# contributed by Greg Buchholz
use strict;
my $w=shift;
my $h=$w;
my $limit = 2; my $limit_sqr = $limit * $limit;
my $iter = 50;
print "P4\n$w $h\n";
my $Zr, my $Zi, my $Cr, my $Ci, my $Tr, my $Ti;
my $byte_acc=0, my $bit_num=0;
for my $y (0..$h-1)
{
for my $x (0..$w-1)
{
$Zr= 0; $Zi=0;
$Cr = (2*$x/$w - 1.5); $Ci=(2*$y/$h - 1);
for (1..$iter)
{
$Tr = $Zr*$Zr - $Zi*$Zi + $Cr;
$Ti = 2*$Zr*$Zi + $Ci;
$Zr = $Tr; $Zi = $Ti;
last if ($Zr*$Zr+$Zi*$Zi>$limit_sqr);
}
$byte_acc*=2;
$byte_acc++ unless ($Zr*$Zr+$Zi*$Zi>$limit_sqr);
$bit_num++;
if($bit_num == 8)
{
print chr($byte_acc);
$byte_acc = 0;
$bit_num = 0;
}
elsif($x == $w-1)
{
$byte_acc = $byte_acc * 2**(8-$w%8);
print chr($byte_acc);
$byte_acc = 0;
$bit_num = 0;
}
}
}
notes, command-line, and program output
NOTES:
64-bit Ubuntu quad core
This is perl 5, version 38
subversion 2 (v5.38.2)
x86_64-linux-thread-multi
Sat, 02 Mar 2024 22:47:57 GMT
COMMAND LINE:
/opt/src/perl-5.38.2/bin/perl simple.perl-2.perl 16000
(BINARY) PROGRAM OUTPUT NOT SHOWN