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.450.4620,324724  2% 2% 0% 100%
4,0003.453.4523,392724  1% 1% 2% 100%
16,00048.7448.7656,644724  1% 2% 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

java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) Server VM (build 25.25-b02, mixed mode)

Scala compiler version 2.11.4 -- 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 Nov 2014 07:36:00 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.11.4/bin/scalac -optimise -target:jvm-1.8 mandelbrot.scala
4.37s to complete and log all make actions

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

(BINARY) PROGRAM OUTPUT NOT SHOWN

Revised BSD license

  Home   Conclusions   License   Play