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
250,000Failed  1287   

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

Read k-nucleotide 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

 k-nucleotide Scala #4 program source code

/* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/
 * contributed by Rex Kerr
 * (based partially on the single-threaded version by Isaac Gouy
 * with fixes from Iulian Dragos and Meiko Rachimow)
 */

import java.io._
import scala.collection.mutable._
import scala.actors._
import Actor.loop

object knucleotide {
  class ShiftScan(offset:Int, stride:Int) extends Actor {
    val bag = new HashBag
    def findFreq(s:String, j:Int) = {
      val n = s.length - j + 1
      var i = offset
      while (i < n) {
        bag(s.substring(i,i+j)).inc
        i += j
      }
      bag
    }
    def act() { loop { react {
      case seq : String =>
        sender ! findFreq(seq,stride)
        exit
    }}}
  }

  class SizeScan(length:Int, boss:Actor) extends Actor {
    var bags = List[HashBag]()
    val workers = (0 until length).map(new ShiftScan(_,length))
    def act() { loop { react {
      case b : HashBag =>
        bags = b :: bags
        if (bags.length==workers.length) {
          boss ! (bags.head /: bags.tail)(_ ++ _)
          exit
        }
      case seq : String =>
        workers.foreach(_.start ! seq)
    }}}
  }

  class Scan(work : String*) extends Actor {
    val lengths = work.map(_.length)
    val freqs = work.filter(_(0)=='*').map(_.length)
    val counts = work.filter(_(0)!='*')
    val scans = new HashMap[Int,HashBag]()
    var seq_len = 0
     
    def writeFreqs(j : Int) {
      val n  = 1.0 + seq_len - j
      val sorted = scans(j).elements.toList.sort(
        (a,b) => (a.value>b.value) || (a.value==b.value && a.key > b.key)
      )
      sorted.foreach(a => printf(a.key + " %.3f\n", a.value * 100.0 / n))
      println
    }
     
    def act() { loop { react {
      case seq : String =>
        seq_len = seq.length
        lengths.foreach(l => new SizeScan(l,this).start() ! seq)
      case h : HashBag =>
        val n = h.elements.next.key.length
        scans(n) = h
        if (lengths.forall(scans contains _)) {
          freqs.foreach(writeFreqs(_))
          counts.foreach(s => println(scans(s.length)(s).value + "\t" + s))
          exit
        }
    }}}
  }

  def readSequence(id: String, r: BufferedReader) = {
    val b = new java.lang.StringBuilder()
     
    var line = r.readLine
    while (line != null) {
      if (line(0)=='>' && line.startsWith(id)) line = null
      else line = r.readLine
    }
     
    line = r.readLine
    while (line != null) {
      if (line(0)=='>') line = null
      else {
        b.append(line.toUpperCase)
        line = r.readLine
      }
    }
    b.toString
  }
  
  def main(args: Array[String]) {
    val r = new BufferedReader(new InputStreamReader(System.in))
    val seq = readSequence(">THREE",r)
    r.close
      
    val scanner = new Scan("*","**","GGT","GGTA","GGTATT",
                           "GGTATTTTAATT","GGTATTTTAATTTATAGT")
    scanner.start() ! seq
  }
}

class HashBag extends HashTable[String] {
  class Counter(val key: String, var value: Int)
        extends HashEntry[String,Counter]
  {
    def inc { value += 1 }
    def +=(i:Int) { value += i }
  }

  protected type Entry = Counter
  protected def entryKey(e: Entry) = e.key
  def elements = entries
   
  def apply(key:String): Counter = {
    var bucket = table(index(elemHashCode(key))).asInstanceOf[Entry]
    while (bucket ne null) {
      if (elemEquals(entryKey(bucket),key)) return bucket
      bucket = bucket.next
    }
    bucket = new Entry(key,0)
    addEntry(bucket)
    bucket
  }
     
  def ++(h : HashBag) : HashBag = {
    h.elements.foreach(kv => this(kv.key) += kv.value)
    this
  }
}

 make, command-line, and program output logs

Wed, 19 Mar 2014 07:09:10 GMT

MAKE:
mv knucleotide.scala-4.scala knucleotide.scala
/usr/local/src/scala-2.10.3/bin/scalac -optimise -target:jvm-1.7 knucleotide.scala
knucleotide.scala:109: error: wrong number of type arguments for scala.collection.mutable.HashTable, should be 2
class HashBag extends HashTable[String] {
                      ^
knucleotide.scala:119: error: not found: value entries
  def elements = entries
                 ^
knucleotide.scala:122: error: not found: value table
    var bucket = table(index(elemHashCode(key))).asInstanceOf[Entry]
                 ^
knucleotide.scala:124: error: not found: value elemEquals
      if (elemEquals(entryKey(bucket),key)) return bucket
          ^
knucleotide.scala:128: error: not found: value addEntry
    addEntry(bucket)
    ^
5 errors found
make: [knucleotide.scala-4.scala_run] Error 1 (ignored)
2.67s to complete and log all make actions

COMMAND LINE:
env JAVA_OPTS=-Xmx3G /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 knucleotide 0 < knucleotide-input250000.txt

PROGRAM FAILED 


PROGRAM OUTPUT:

Error: Could not find or load main class knucleotide

Revised BSD license

  Home   Conclusions   License   Play