Package

wvlet.log

io

Permalink

package io

Visibility
  1. Public
  2. All

Type Members

  1. trait ResourceReader extends AnyRef

    Permalink

    Extend this trait to add support your class for reading resources

  2. class StopWatch extends AnyRef

    Permalink
  3. trait TimeReport extends Ordered[TimeReport]

    Permalink

    Summary of the execution times of the code blocks

  4. trait Timer extends Serializable

    Permalink

    Timer trait measures the performance of code blocks.

    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.

Value Members

  1. object IOUtil

    Permalink

  2. object Resource

    Permalink

    Resource file manager.

Ungrouped