Packages

t

wvlet.log.io

Timer

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
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def block[A](name: String)(f: ⇒ A): TimeReport
    Attributes
    protected
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native() @HotSpotIntrinsicCandidate()
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  15. def reportLog(m: TimeReport, logLevel: LogLevel): Unit
    Attributes
    protected
  16. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  17. def time[A](blockName: String, logLevel: LogLevel = INFO, repeat: Int = 1, blockRepeat: Int = 1)(f: ⇒ A): TimeReport

    Measure the execution time of the code block

    Measure the execution time of the code block

    repeat

    the number of repetitive execution

    Attributes
    protected
  18. def toString(): String
    Definition Classes
    AnyRef → Any
  19. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  21. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] ) @Deprecated
    Deprecated

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped