The Computer Language
24.11 Benchmarks Game

mandelbrot Ruby yjit #8 program

source code

# The Computer Language Benchmarks Game
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
   
# line-by-line from Greg Buchholz's C program





def main(n)

    w, h, bit_num = 0, 0, 0, 0, 0
    byte_acc = 0
    i, iter = 0, 50
    x, y, limit = 2.0, 2.0, 2.0
    zr, zi, cr, ci, tr, ti = 0.0, 0.0, 0.0, 0.0, 0.0, 0.0

    h = ARGV[0].to_i; w = h

    puts "P4\n#{w} #{h}"

    h.times do |y|

        w.times do |x|

            zr, zi, tr, ti = 0.0, 0.0, 0.0, 0.0
            cr = 2.0*x/w - 1.5; ci = 2.0*y/h - 1.0

            iter.times do
                if tr+ti <= limit*limit            
                    zi = 2.0*zr*zi + ci;
                    zr = tr - ti + cr;
                    tr = zr * zr;
                    ti = zi * zi;
                end
            end            
            byte_acc = byte_acc << 1  
            if tr+ti <= limit*limit then byte_acc = byte_acc | 0x01 end            

            bit_num += 1        
                
            if bit_num == 8       
                print byte_acc.chr
                byte_acc = 0; 
                bit_num = 0     

                
            elsif x == w-1 
                        
                byte_acc = byte_acc << (8-w%8)         
                print byte_acc.chr
                byte_acc = 0; 
                bit_num = 0           
            end                          
       end
    end
end

n = (ARGV[0] || 200).to_i 
main n
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
ruby 3.3.5
(2024-09-03
revision ef084cc8f4)
+YJIT [x86_64-linux]


 Fri, 08 Nov 2024 00:44:06 GMT

COMMAND LINE:
 /opt/src/ruby-3.3.5/bin/ruby --yjit -W0 mandelbrot.ruby-8.ruby 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN