/mobile Handheld Friendly website

 performance measurements

Each table row shows performance measurements for this Dart program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
1,0000.540.5436,672809  2% 0% 4% 100%
4,0004.164.1687,200809  0% 1% 0% 100%
16,00056.1856.19212,480809  0% 0% 0% 100%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read mandelbrot benchmark to see what this program should do.

 notes

Dart VM version: 0.4.7.1_r21537 (Tue Apr 16 01:34:51 2013)

 mandelbrot Dart program source code

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

   contributed by Jos Hirth, 
   calculation block borrowed from the C# version which was 
      created by Isaac Gouy, Antti Lankila, The Anh Tran, and Robert F. Tobler
*/

import 'dart:io';
import 'dart:isolate';
import 'dart:async';
import 'dart:typeddata';

void main() {
  int n = ((){
    var args = new Options().arguments;
    return args.length > 0 ? int.parse(args[0]) : 200;
  }());

  var threads = Platform.numberOfProcessors;
  var ports = new List(threads);
  var segmentFutures = new List(threads);
  int lineLen = (n - 1) ~/ 8 + 1;
  var lines = new List<Int8List>(n);

  var segmentSize = new List.filled(threads, n ~/ threads);
  segmentSize[0] += n % threads;

  var from = 0;
  for (int i = 0; i < threads; i++) {
    var len = segmentSize[i];
    ports[i] = spawnFunction(calculateSegment);
    segmentFutures[i] = ports[i].call({
      'n': n,
      'from': from,
      'len': len
    });
    from += len;
  }

  stdout.write('P4\n$n $n\n');

  Future.wait(segmentFutures).then((segments) {
    for (var segment in segments) {
      for (var line in segment) {
        stdout.add(line);
      }
    }
  });
}

Int8List calculateLine (int n, int y) {
  int lineLen = (n - 1) ~/ 8 + 1;

  var line = new Int8List(lineLen);

  int xbyte = 0, bits = 1;
  double ci = y * 2.0 / n - 1.0;

  for (int x = 0; x < n; x++) {
    double cr = x * 2.0 / n - 1.5;
    if (bits > 0xff) {
      line[xbyte++] = bits;
      bits = 1;
    }
    double zr = cr,
        zi = ci,
        tr = cr * cr,
        ti = ci * ci;
    int i = 49;
    do {
      zi = zr * zi + zr * zi + ci;
      zr = tr - ti + cr;
      tr = zr * zr;
      ti = zi * zi;
    } while ((tr + ti <= 4.0) && (--i > 0));
    bits = (bits << 1) | (i == 0 ? 1 : 0);
  } while (bits < 0x100) bits = (bits << 1);
  line[xbyte] = bits;

  return line;
}

void calculateSegment () {
  port.receive((msg, replyTo) {
    int n = msg['n'];
    int from = msg['from'];
    int len = msg['len'];

    var lines = new List<Int8List>(len);
    for (int i = 0; i < len; i++) {
      lines[i] = calculateLine(n, from + i);
    }

    replyTo.send(lines);
  });
}

 make, command-line, and program output logs

Sun, 21 Apr 2013 16:32:19 GMT

COMMAND LINE:
/usr/local/src/dart-sdk/bin/dart  mandelbrot.dart 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN

Revised BSD license

  Home   Conclusions   License   Play