The Computer Language
Benchmarks Game

mandelbrot TypeScript program

source code

/* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/

   direct transliteration of Greg Buchholz's C program
   contributed by Isaac Gouy
*/

/// <reference path="./Include/node/index.d.ts" />

const w = +process.argv[2]
const h = w

let bit_num = 0, i = 0, byte_acc = 0
const iter = 50, limit = 2.0
let Zr, Zi, Cr, Ci, Tr, Ti

process.stdout.write( "P4\n" + w + " " + h + "\n" )

for (let y = 0; y < h; ++y) {
   for (let 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 (let i = 0; i < iter && (Tr+Ti <= limit*limit); ++i) {
         Zi = 2.0*Zr*Zi + Ci
         Zr = Tr - Ti + Cr
         Tr = Zr * Zr
         Ti = Zi * Zi
      }

      byte_acc <<= 1
      if (Tr+Ti <= limit*limit) { byte_acc |= 0x01 }

      ++bit_num

      if (bit_num == 8) {
         process.stdout.write( String.fromCharCode(byte_acc),'ascii' )
         byte_acc = 0
         bit_num = 0
      }
      else if (x == w-1) {
         byte_acc <<= (8-w%8)
         process.stdout.write( String.fromCharCode(byte_acc),'ascii' )
         byte_acc = 0
         bit_num = 0
      }
   }
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
Version 2.5.2
node.js v8.4.0


Fri, 01 Sep 2017 20:04:42 GMT

MAKE:
mv mandelbrot.typescript mandelbrot.ts
/usr/local/src/node-v8.4.0-linux-x64/bin/tsc --alwaysStrict -t ESNEXT  mandelbrot.ts

3.22s to complete and log all make actions

COMMAND LINE:
/usr/local/src/node-v8.4.0-linux-x64/bin/node --use_strict mandelbrot.js 16000

PROGRAM FAILED 


(BINARY) PROGRAM OUTPUT NOT SHOWN

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/usr/local/src/node-v8.4.0-linux-x64/bin/node]
 2: 0x13740dc [/usr/local/src/node-v8.4.0-linux-x64/bin/node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [/usr/local/src/node-v8.4.0-linux-x64/bin/node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/src/node-v8.4.0-linux-x64/bin/node]
 5: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/src/node-v8.4.0-linux-x64/bin/node]
 6: v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/src/node-v8.4.0-linux-x64/bin/node]
 7: 0x385ee68840dd