/mobile Handheld Friendly website

 performance measurements

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

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
1,0000.540.28248724  32% 29% 34% 100%
4,0003.691.0819,944724  82% 98% 82% 81%
16,00050.9212.9249,556724  100% 98% 98% 98%

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

java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Server VM (build 25.0-b70, mixed mode)

Scala compiler version 2.10.3 -- Copyright 2002-2013, LAMP/EPFL

 mandelbrot Scala program source code

/* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/
   original contributed by Isaac Gouy
   made to use single array and parallelized by Stephen Marsh
   converted to Scala 2.8 by Rex Kerr
*/

import java.io.BufferedOutputStream

object mandelbrot {
  var size: Int = 0
  var bytesPerRow: Int = 0
  var bitmap: Array[Byte] = _
  var donerows: Array[Boolean] = _
  var nextRow = 0
  val limitSquared = 4.0
  val max = 50

  def getNextRow: Int = synchronized {
    notify() // wakes up main thread
    if (nextRow == size) return -1
    nextRow += 1
    return nextRow - 1
  }

  def main(args: Array[String]) {
    size = args(0).toInt
    bytesPerRow = (size+7)/8 // ceiling of (size / 8)
    bitmap = new Array(bytesPerRow*size)
    donerows = new Array(size)

    for (i <- 0 until Runtime.getRuntime().availableProcessors())
      new Thread(new CalcThread()).start()

    // main thread prints rows as they finish
    println("P4\n" + size + " " + size)
    val w = new BufferedOutputStream(System.out)
    var y = 0
    while (y < size) {
      while (!donerows(y)) synchronized{wait()}
      w.write(bitmap, y * bytesPerRow, bytesPerRow)
      y += 1
    }
    w.close
  }

  class CalcThread extends Runnable {
    def run () {
      while (true) {
	var y = getNextRow
	if (y == -1) return

	var bits = 0
	var bitnum = 0
	var x = 0
	var aindex = y * bytesPerRow

	while (x < size) {

        val cr = 2.0 * x / size - 1.5
        val ci = 2.0 * y / size - 1.0

        var zr, tr, zi, ti = 0.0

        var j = max
            do {
              zi = 2.0 * zr * zi + ci
              zr = tr - ti + cr
              ti = zi*zi
              tr = zr*zr

              j = j - 1
            } while (!(tr + ti > limitSquared) && j > 0)

         bits = bits << 1
         if (!(tr + ti > limitSquared)) bits += 1
         bitnum += 1

         if (x == size - 1) {
           bits = bits << (8 - bitnum)
           bitnum = 8
         }

         if (bitnum == 8) {
           bitmap(aindex) = bits.toByte
	   aindex += 1
           bits = 0
           bitnum = 0
         }

         x += 1
	}
	donerows(y) = true
      }
    }
  }
}

 make, command-line, and program output logs

Wed, 19 Mar 2014 07:25:02 GMT

MAKE:
mv mandelbrot.scala mandelbrot.scala
mv: ‘mandelbrot.scala’ and ‘mandelbrot.scala’ are the same file
make: [mandelbrot.scala_run] Error 1 (ignored)
/usr/local/src/scala-2.10.3/bin/scalac -optimise -target:jvm-1.7 mandelbrot.scala
4.21s to complete and log all make actions

COMMAND LINE:
 /usr/local/src/jdk1.8.0/bin/java -server -XX:+TieredCompilation -XX:+AggressiveOpts  -Xbootclasspath/a:/usr/local/src/scala-2.10.3/lib/scala-library.jar:/usr/local/src/scala-2.10.3/lib/akka-actors.jar:/usr/local/src/scala-2.10.3/lib/typesafe-config.jar mandelbrot 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN

Revised BSD license

  Home   Conclusions   License   Play