Trait

wvlet.log.io

Timer

Related Doc: package io

Permalink

trait Timer extends Serializable

Timer trait measures the performance of code blocks. Extend this trait and wrap the code to measure with time(code_name){ ... }:

class A extends Timer {
  val t : TimeReport = time("performance test") {
    // write any code here
    block("A") {
      // code A
    }
    block("B") {
     // code B
    }
  }
  // report elapsed time of A, B and the total running time
  println(t)

  t("A").average // the average of running time of code block "A" (min and max are also available)
}

Timer can take the average of repetitive executions:

class Rep extends Timer {

  // Repeat 10 times the evaluation of the whole block
  val t = time("repetitive evaluation", repeat=10) {
     // This part will be executed 1000 x 10 times
     block("A", repeat=1000) {
       // code A
     }

     // This part will be executed 1000 x 10 times
     block("B", repeat=1000) {
       // code B
     }
  }

  println(t)

  // Which code is faster?
  if(t("A") <= t("B"))
     println("A is faster")
  else
     println("B is faster")
}

When measuring Scala (Java) code performances, you should take the average of execution times and reorder the code block execution orders, because JVM has JIT compiler, which optimizes the code at runtime. And also cache usage and the running state of the garbage core (GC) affects the code performance. By repeating the executions of the entire or individual blocks with the repeat option, you can avoid such pitfalls of benchmarking.

Linear Supertypes
Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Timer
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def block[A](name: String)(f: ⇒ A): TimeReport

    Permalink
    Attributes
    protected
  6. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  11. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. def reportLog(m: TimeReport, logLevel: LogLevel): Unit

    Permalink
    Attributes
    protected
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  18. def time[A](blockName: String, logLevel: LogLevel = INFO, repeat: Int = 1, blockRepeat: Int = 1)(f: ⇒ A): TimeReport

    Permalink

    Measure the execution time of the code block

    Measure the execution time of the code block

    repeat

    the number of repetitive execution

    Attributes
    protected
  19. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  20. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped