The Computer Language
24.09 Benchmarks Game

simple Matz's Ruby #2 program

source code

# The Computer Language Benchmarks Game
#  https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
#   
#   contributed by Karl von Laudermann

size = ARGV[0].to_i

puts "P4\n#{size} #{size}"

iter = 50
limit = 2.0
byte_acc = 0
bit_num = 0

size.times do |y|
     size.times do |x|
         zr = 0.0
         zi = 0.0
         cr = (2.0*x/size)-1.5
         ci = (2.0*y/size)-1.0
         escape = false

         iter.times do
            tr = zr*zr - zi*zi + cr
            ti = 2*zr*zi + ci
            zr, zi = tr, ti

            if (zr*zr+zi*zi) > (limit*limit)
                escape = true
                break
            end
         end

         byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1)
         bit_num += 1

         if (bit_num == 8) || (x == size - 1)
             byte_acc <<= (8 - bit_num)
             print byte_acc.chr
             byte_acc = 0
             bit_num = 0
         end
     end
end
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
ruby 1.8.7 
(2014-01-28
patchlevel 376)
[x86_64-linux]



 Sun, 09 Jun 2024 15:57:20 GMT

COMMAND LINE:
 /usr/share/rvm/rubies/ruby-1.8.7-head/bin/ruby  simple.mri-2.mri 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN