o

App.Benchmark

object Benchmark

App.Benchmark is a simple comparison testing tool

JVM technology makes it difficult to get absolute performance data

App.Benchmark allows to run several targets side by side, comparing their performance against each other

The result presents three values:

  • 'Run count' is the number of times the target executed. The time frame is equal for all targets
  • 'Memory' is the average memory increase for all executions. This is even less precise measurement, however for side by side comparison is somewhat valuable
  • 'Control Value Avg' is the average of target returns. This can be used for validity check. In best case, all targets should arrive to the same value in different ways

Let's test folding performance for List, Vector and Array

// Int values from 0 to 100 shuffled

val v: Vector[Int] = (1 <> 100).all.shuffle.to[Vector]
val l: List[Int] = v.toList
val a: Array[Int] = v.toArray

App.Benchmark(10.Seconds,
  ("List   ", () => l.fold(0)(_ + _)),
  ("Vector ", () => v.fold(0)(_ + _)),
  ("Array  ", () => a.fold(0)(_ + _)))

// Output
Final Result.  Total Duration 10 secs
--- ------- --------- --- ------ --- -----------------
Num Name    Run Count %   Memory %   Control Value Avg
--- ------- --------- --- ------ --- -----------------
1   List    2.5m      51  1.4kB  86  5050
2   Vector  2.0m      41  1.7kB  100 5050
3   Array   4.9m      100 1.5kB  90  5050
--- ------- --------- --- ------ --- -----------------
Ordering
  1. Alphabetic
Inherited
  1. Benchmark
  2. scala.AnyRef
  3. scala.Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Method

  1. def apply[A](totalTime: Duration, targets: (String, () ⇒ A)*)(implicit arg0: Numeric[A]): Unit

    Run with defaults

    Run with defaults

    Runs test for the totalTime specified

    A number of trials will be generated automatically

    totalTime

    total time allowed for the test

    targets

    a list of tuples, each representing target name and target function to run. The function return will be converted to Long and average value will be displayed in the results

    Definition Classes
    Benchmark
  2. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  3. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  4. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  5. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  7. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  8. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  9. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. final def notify(): Unit
    Definition Classes
    AnyRef
  11. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  12. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  13. def toString(): String
    Definition Classes
    AnyRef → Any
  14. def trials[A](trialCount: Int, trialLength: Duration, gcPause: Duration, targets: (String, () ⇒ A)*)(implicit arg0: Numeric[A]): Unit

    Run specified number of trials

    Run specified number of trials

    All trials are accumulated into final result

    trialCount

    number of trials to run

    trialLength

    length of each trial

    gcPause

    garbage collection pause, after each trial

    targets

    a list of tuples, each representing target name and target function to run. The function return will be converted to Long and average value will be displayed in the results

    Definition Classes
    Benchmark
  15. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  16. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  17. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Operator

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
Linear Supertypes
AnyRef, Any
Source: Benchmark.scala