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="/usr/local/src/typescript/node.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:
32-bit Ubuntu one core
Version 2.0.3
node.js v6.9.0


Wed, 19 Oct 2016 19:28:31 GMT

MAKE:
mv mandelbrot.typescript mandelbrot.ts
/usr/local/src/node-v6.9.0-linux-x86/bin/tsc  mandelbrot.ts
../../../../../usr/local/src/typescript/node.d.ts(393,11): error TS2430: Interface 'NodeBuffer' incorrectly extends interface 'Uint8Array'.
  Types of property 'fill' are incompatible.
    Type '(value: any, offset?: number, end?: number) => Buffer' is not assignable to type '(value: number, start?: number, end?: number) => this'.
      Type 'Buffer' is not assignable to type 'this'.
/home/dunham/benchmarksgame/nanobench/makefiles/u32.programs.Makefile:601: recipe for target 'mandelbrot.typescript_run' failed
make: [mandelbrot.typescript_run] Error 2 (ignored)
/usr/local/src/node-v6.3.0-linux-x86/lib/node_modules/babel-cli/bin/babel.js --plugins transform-es2015-modules-commonjs mandelbrot.js -o mandelbrot.js
make: /usr/local/src/node-v6.3.0-linux-x86/lib/node_modules/babel-cli/bin/babel.js: Command not found
/home/dunham/benchmarksgame/nanobench/makefiles/u32.programs.Makefile:601: recipe for target 'mandelbrot.typescript_run' failed
make: [mandelbrot.typescript_run] Error 127 (ignored)
2.70s to complete and log all make actions

COMMAND LINE:
/usr/local/src/node-v6.9.0-linux-x86/bin/node --use_strict mandelbrot.js 16000

PROGRAM FAILED 


(BINARY) PROGRAM OUTPUT NOT SHOWN

FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
 2: 0x8c7b5c6 [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
 3: v8::Utils::ReportApiFailure(char const*, char const*) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
 5: v8::internal::MarkCompactCollector::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject*) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
 6: v8::internal::MarkCompactCollector::VisitLiveObjects(v8::internal::MemoryChunk*, v8::internal::MarkCompactCollector::HeapObjectVisitor*, v8::internal::MarkCompactCollector::IterationMode) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
 7: v8::internal::PageParallelJob<v8::internal::EvacuationJobTraits>::Task::RunInternal() [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
 8: v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
 9: v8::internal::MarkCompactCollector::EvacuateNewSpaceAndCandidates() [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
10: v8::internal::MarkCompactCollector::CollectGarbage() [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
11: v8::internal::Heap::MarkCompact() [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
12: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
13: v8::internal::Heap::CollectGarbage(v8::internal::GarbageCollector, char const*, char const*, v8::GCCallbackFlags) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
14: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
15: v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
16: 0x30f0ac86
17: 0x49e49d00
18: 0x30f0bc36
19: 0x49e46325
20: 0x49e44210
21: 0x49e4802a
22: 0x49e333c8
23: 0x49e2df2e
24: 0x49e2ce3a
25: 0x49e2caba
26: 0x49e24c79
27: 0x49e248c2
28: 0x49e247b8
29: 0x30f3b1b2
30: 0x30f37606
31: 0x30f327fe
32: 0x30f218c3
33: v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
34: v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
35: v8::Function::Call(v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
36: node::LoadEnvironment(node::Environment*) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
37: node::Start(int, char**) [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
38: main [/usr/local/src/node-v6.9.0-linux-x86/bin/node]
39: __libc_start_main [/lib/i386-linux-gnu/libc.so.6]