The Computer Language
24.09 Benchmarks Game

simple Toit program

source code

/* The Computer Language Benchmarks game
   https://salsa.debian.org/benchmarksgame-team/benchmarksgame/

   transliterated from Greg Buchholz's C program by Isaac Gouy 
*/  

import host.pipe
    
main args:
  bit-num := 0; 
  iter ::= 50; limit ::= 2.0
  zr := ?; zi := ?; cr := ?; ci := ?; tr := ?; ti := ?

  h ::= args.size == 1 ? int.parse args[0] : 200; w ::= h
  byte-acc ::= #[0]
  
  print "P4\n$w $h"
  out := pipe.stdout  

  for y := 0; y < h; ++y:   
    for  x := 0; x < w; ++x:
      zr = 0.0; zi = 0.0; tr = 0.0; ti = 0.0
      cr = 2.0 * x / w - 1.5
      ci = 2.0 * y / h - 1.0
      for i := 0; i < iter and (tr + ti <= limit * limit); ++i:
        zi = 2.0 * zr * zi + ci
        zr = tr - ti + cr
        tr = zr * zr
        ti = zi * zi
        
      byte-acc[0] <<= 1;
      if  tr + ti <= limit * limit: byte-acc[0] |= 0x01;
      ++bit-num       
        
      if bit-num == 8:
        out.write byte-acc     
        byte-acc[0] = 0
        bit-num = 0 
      else:
        if x == w - 1:
          byte-acc[0] <<= (8 - w % 8)
          out.write byte-acc             
          byte-acc[0] = 0
          bit-num = 0
          
  out.close       
  
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
v2.0.0-alpha.163



 Tue, 08 Oct 2024 01:46:17 GMT

MAKE:
cp -r Include/toit/.packages .
cp -r Include/toit/package.lock .
cp -r Include/toit/package.yaml .	
/opt/src/toit/bin/toit.compile -O2 --strip -o simple.toit_run simple.toit 

1.20s to complete and log all make actions

COMMAND LINE:
 ./simple.toit_run 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN