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
Ordering
- Alphabetic
- By Inheritance
Inherited
- Timer
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
Visibility
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
block[A](name: String)(f: ⇒ A): TimeReport
- Attributes
- protected
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
reportLog(m: TimeReport, logLevel: LogLevel): Unit
- Attributes
- protected
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
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
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
Deprecated Value Members
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] ) @Deprecated
- Deprecated