SlideShare a Scribd company logo
ScalaMeter 
Performance regression testing framework 
Aleksandar Prokopec, Josh Suereth
Goal 
List(1 to 100000: _*).map(x => x * x) 
26 ms
Goal 
List(1 to 100000: _*).map(x => x * x) 
class List[+T] 
extends Seq[T] { 
// implementation 1 
} 
26 ms
Goal 
List(1 to 100000: _*).map(x => x * x) 
class List[+T] 
extends Seq[T] { 
// implementation 1 
} 
26 ms
Goal 
List(1 to 100000: _*).map(x => x * x) 
class List[+T] 
extends Seq[T] { 
// implementation 2 
} 
49 ms
First example 
def measure() { 
val buffer = mutable.ArrayBuffer(0 until 2000000: _*) 
val start = System.currentTimeMillis() 
var sum = 0 
buffer.foreach(sum += _) 
val end = System.currentTimeMillis() 
println(end - start) 
}
First example 
def measure() { 
val buffer = mutable.ArrayBuffer(0 until 2000000: _*) 
val start = System.currentTimeMillis() 
var sum = 0 
buffer.foreach(sum += _) 
val end = System.currentTimeMillis() 
println(end - start) 
}
First example 
def measure() { 
val buffer = mutable.ArrayBuffer(0 until 2000000: _*) 
val start = System.currentTimeMillis() 
var sum = 0 
buffer.foreach(sum += _) 
val end = System.currentTimeMillis() 
println(end - start) 
}
First example 
def measure() { 
val buffer = mutable.ArrayBuffer(0 until 2000000: _*) 
val start = System.currentTimeMillis() 
var sum = 0 
buffer.foreach(sum += _) 
val end = System.currentTimeMillis() 
println(end - start) 
}
First example 
def measure() { 
val buffer = mutable.ArrayBuffer(0 until 2000000: _*) 
val start = System.currentTimeMillis() 
var sum = 0 
buffer.foreach(sum += _) 
val end = System.currentTimeMillis() 
println(end - start) 
} 
measure()
First example 
def measure() { 
val buffer = mutable.ArrayBuffer(0 until 2000000: _*) 
val start = System.currentTimeMillis() 
var sum = 0 
buffer.foreach(sum += _) 
val end = System.currentTimeMillis() 
println(end - start) 
} 
measure() 
26 ms
The warmup problem 
def measure() { 
val buffer = mutable.ArrayBuffer(0 until 2000000: _*) 
val start = System.currentTimeMillis() 
var sum = 0 
buffer.foreach(sum += _) 
val end = System.currentTimeMillis() 
println(end - start) 
} 
measure() 
measure() 
26 ms, 11 ms
The warmup problem 
def measure() { 
val buffer = mutable.ArrayBuffer(0 until 2000000: _*) 
val start = System.currentTimeMillis() 
var sum = 0 
buffer.foreach(sum += _) 
val end = System.currentTimeMillis() 
println(end - start) 
} 
measure() 
measure() 
26 ms, 11 ms 
Why? 
Mainly: 
- JIT compilation 
- dynamic optimization
The warmup problem 
def measure() { 
val buffer = mutable.ArrayBuffer(0 until 2000000: _*) 
val start = System.currentTimeMillis() 
var sum = 0 
buffer.foreach(sum += _) 
val end = System.currentTimeMillis() 
println(end - start) 
} 
45 ms, 10 ms 
26 ms, 11 ms
The warmup problem 
def measure2() { 
val buffer = mutable.ArrayBuffer(0 until 4000000: _*) 
val start = System.currentTimeMillis() 
buffer.map(_ + 1) 
val end = System.currentTimeMillis() 
println(end - start) 
}
The warmup problem 
def measure2() { 
val buffer = mutable.ArrayBuffer(0 until 4000000: _*) 
val start = System.currentTimeMillis() 
buffer.map(_ + 1) 
val end = System.currentTimeMillis() 
println(end - start) 
} 
241, 238, 235, 236, 234
The warmup problem 
def measure2() { 
val buffer = mutable.ArrayBuffer(0 until 4000000: _*) 
val start = System.currentTimeMillis() 
buffer.map(_ + 1) 
val end = System.currentTimeMillis() 
println(end - start) 
} 
241, 238, 235, 236, 234, 429
The warmup problem 
def measure2() { 
val buffer = mutable.ArrayBuffer(0 until 4000000: _*) 
val start = System.currentTimeMillis() 
buffer.map(_ + 1) 
val end = System.currentTimeMillis() 
println(end - start) 
} 
241, 238, 235, 236, 234, 429, 209
The warmup problem 
def measure2() { 
val buffer = mutable.ArrayBuffer(0 until 4000000: _*) 
val start = System.currentTimeMillis() 
buffer.map(_ + 1) 
val end = System.currentTimeMillis() 
println(end - start) 
} 
241, 238, 235, 236, 234, 429, 209, 194, 195, 195
The warmup problem 
Bottomline: benchmark has to be repeated until the running time becomes “stable”. 
The number of repetitions is not known in advance. 
241, 238, 235, 236, 234, 429, 209, 194, 195, 195
Warming up the JVM 
241, 238, 235, 236, 234, 429, 209, 194, 195, 195, 
194, 194, 193, 194, 196, 195, 195 
Can this be automated? 
Idea: measure variance of the running times. 
When it becomes sufficiently small, the test has stabilized.
The interference problem 
val buffer = ArrayBuffer(0 until 900000: _*) 
buffer.map(_ + 1) 
val buffer = ListBuffer(0 until 900000: _*) 
buffer.map(_ + 1)
The interference problem 
Lets measure the first map 3 times with 7 repetitions: 
val buffer = ArrayBuffer(0 until 900000: _*) 
buffer.map(_ + 1) 
val buffer = ListBuffer(0 until 900000: _*) 
buffer.map(_ + 1) 
61, 54, 54, 54, 55, 55, 56 
186, 54, 54, 54, 55, 54, 53 
54, 54, 53, 53, 53, 54, 51
The interference problem 
val buffer = ArrayBuffer(0 until 900000: _*) 
buffer.map(_ + 1) 
val buffer = ListBuffer(0 until 900000: _*) 
buffer.map(_ + 1) 
Now, lets measure the list buffer map in between: 
61, 54, 54, 54, 55, 55, 56 
186, 54, 54, 54, 55, 54, 53 
54, 54, 53, 53, 53, 54, 51 
59, 54, 54, 54, 54, 54, 54 
44, 36, 36, 36, 35, 36, 36 
45, 45, 45, 45, 44, 46, 45 
18, 17, 18, 18, 17, 292, 16 
45, 45, 44, 44, 45, 45, 44
The interference problem 
val buffer = ArrayBuffer(0 until 900000: _*) 
buffer.map(_ + 1) 
val buffer = ListBuffer(0 until 900000: _*) 
buffer.map(_ + 1) 
Now, lets measure the list buffer map in between: 
61, 54, 54, 54, 55, 55, 56 
186, 54, 54, 54, 55, 54, 53 
54, 54, 53, 53, 53, 54, 51 
59, 54, 54, 54, 54, 54, 54 
44, 36, 36, 36, 35, 36, 36 
45, 45, 45, 45, 44, 46, 45 
18, 17, 18, 18, 17, 292, 16 
45, 45, 44, 44, 45, 45, 44
Using separate JVM 
Bottomline: always run the tests in a new JVM.
Using separate JVM 
Bottomline: always run the tests in a new JVM. 
This may not reflect a real-world scenario, but it gives a good idea of how different several alternatives are.
Using separate JVM 
Bottomline: always run the tests in a new JVM. 
It results in a reproducible, more stable measurement.
The List.map example 
val list = (0 until 2500000).toList 
list.map(_ % 2 == 0)
The List.map example 
val list = (0 until 2500000).toList 
list.map(_ % 2 == 0) 
37, 38, 37, 1175, 38, 37, 37, 37, 37, …, 38, 37, 37, 37, 37, 465, 35, 35, …
The garbage collection problem 
val list = (0 until 2500000).toList 
list.map(_ % 2 == 0) 
37, 38, 37, 1175, 38, 37, 37, 37, 37, …, 38, 37, 37, 37, 37, 465, 35, 35, … 
This benchmark triggers GC cycles!
The garbage collection problem 
val list = (0 until 2500000).toList 
list.map(_ % 2 == 0) 
37, 38, 37, 1175, 38, 37, 37, 37, 37, …, 38, 37, 37, 37, 37, 465, 35, 35, … -> mean: 47 ms 
This benchmark triggers GC cycles!
The garbage collection problem 
val list = (0 until 2500000).toList 
list.map(_ % 2 == 0) 
37, 38, 37, 1175, 38, 37, 37, 37, 37, …, 38, 37, 37, 37, 37, 465, 35, 35, … -> mean: 47 ms 
This benchmark triggers GC cycles! 
37, 37, 37, 647, 37, 36, 38, 37, 36, …, 36, 37, 36, 37, 36, 37, 534, 36, 33, … -> mean: 39 ms
The garbage collection problem 
val list = (0 until 2500000).toList 
list.map(_ % 2 == 0) 
37, 38, 37, 1175, 38, 37, 37, 37, 37, …, 38, 37, 37, 37, 37, 465, 35, 35, … -> mean: 47 ms 
This benchmark triggers GC cycles! 
37, 37, 37, 647, 37, 36, 38, 37, 36, …, 36, 37, 36, 37, 36, 37, 534, 36, 33, … -> mean: 39 ms
The garbage collection problem 
val list = (0 until 2500000).toList 
list.map(_ % 2 == 0) 
Solutions: 
-repeat A LOT of times –an accurate mean, but takes A LONG time
The garbage collection problem 
val list = (0 until 2500000).toList 
list.map(_ % 2 == 0) 
Solutions: 
-repeat A LOT of times –an accurate mean, but takes A LONG time 
-ignore the measurements with GC – gives a reproducible value, and less measurements
The garbage collection problem 
val list = (0 until 2500000).toList 
list.map(_ % 2 == 0) 
Solutions: 
-repeat A LOT of times –an accurate mean, but takes A LONG time 
-ignore the measurements with GC – gives a reproducible value, and less measurements 
-how to do this?
The garbage collection problem 
val list = (0 until 2500000).toList list.map(_ % 2 == 0) 
-manually - verbose:gc
Automatic GC detection 
val list = (0 until 2500000).toList list.map(_ % 2 == 0) 
-manually - verbose:gc 
-automatically using callbacks in JDK7 
37, 37, 37, 647, 37, 36, 38, 37, 36, …, 36, 37, 36, 37, 36, 37, 534, 36, 33, …
Automatic GC detection 
val list = (0 until 2500000).toList list.map(_ % 2 == 0) 
-manually - verbose:gc 
-automatically using callbacks in JDK7 
37, 37, 37, 647, 37, 36, 38, 37, 36, …, 36, 37, 36, 37, 36, 37, 534, 36, 33, … 
raises a GC event
The runtime problem 
-there are other runtime events beside GC – e.g. JIT compilation, dynamic optimization, etc. 
-these take time, but cannot be determined accurately
The runtime problem 
-there are other runtime events beside GC – e.g. JIT compilation, dynamic optimization, etc. 
-these take time, but cannot be determined accurately 
-heap state also influences memory allocation patterns and performance
The runtime problem 
-there are other runtime events beside GC – e.g. JIT compilation, dynamic optimization, etc. 
-these take time, but cannot be determined accurately 
-heap state also influences memory allocation patterns and performance 
val list = (0 until 4000000).toList 
list.groupBy(_ % 10) 
(allocation intensive)
The runtime problem 
-there are other runtime events beside GC – e.g. JIT compilation, dynamic optimization, etc. 
-these take time, but cannot be determined accurately 
-heap state also influences memory allocation patterns and performance 
val list = (0 until 4000000).toList list.groupBy(_ % 10) 
120, 121, 122, 118, 123, 794, 109, 111, 115, 113, 110
The runtime problem 
-there are other runtime events beside GC – e.g. JIT compilation, dynamic optimization, etc. 
-these take time, but cannot be determined accurately 
-heap state also influences memory allocation patterns and performance 
val list = (0 until 4000000).toList list.groupBy(_ % 10) 
120, 121, 122, 118, 123, 794, 109, 111, 115, 113, 110 
affects the mean – 116 ms vs 178 ms
Outlier elimination 
120, 121, 122, 118, 123, 794, 109, 111, 115, 113, 110
Outlier elimination 
120, 121, 122, 118, 123, 794, 109, 111, 115, 113, 110 
109, 110, 111, 113, 115, 118, 120, 121, 122, 123, 794 
sort
Outlier elimination 
120, 121, 122, 118, 123, 794, 109, 111, 115, 113, 110 
109, 110, 111, 113, 115, 118, 120, 121, 122, 123, 794 
sort 
inspect tail and its variance contribution 
109, 110, 111, 113, 115, 118, 120, 121, 122, 123
Outlier elimination 
120, 121, 122, 118, 123, 794, 109, 111, 115, 113, 110 
109, 110, 111, 113, 115, 118, 120, 121, 122, 123, 794 
sort 
inspect tail and its variance contribution 
109, 110, 111, 113, 115, 118, 120, 121, 122, 123 
109, 110, 111, 113, 115, 118, 120, 121, 122, 123, 124 
redo the measurement
Doing all this manually
ScalaMeter 
Does all this analysis automatically, highly configurable. Plus, it detects performance regressions. And generates reports.
ScalaMeter example 
object ListTest extends PerformanceTest.Microbenchmark { 
A range of predefined benchmark types
ScalaMeter example 
object ListTest extends PerformanceTest.Microbenchmark { val sizes = Gen.range("size”)(500000, 1000000, 100000) 
Generators provide input data for tests
ScalaMeter example 
object ListTest extends PerformanceTest.Microbenchmark { val sizes = Gen.range("size”)(500000, 1000000, 100000) val lists = for (sz <- sizes) yield (0 until sz).toList 
Generators can be composed a la ScalaCheck
ScalaMeter example 
object ListTest extends PerformanceTest.Microbenchmark { val sizes = Gen.range("size”)(500000, 1000000, 100000) val lists = for (sz <- sizes) yield (0 until sz).toList using(lists) in { xs => xs.groupBy(_ % 10) } } 
Concise syntax to specify and group tests
ScalaMeter example 
object ListTest extends PerformanceTest.Microbenchmark { val sizes = Gen.range("size”)(500000, 1000000, 100000) val lists = for (sz <- sizes) yield (0 until sz).toList measure method “groupBy” in { using(lists) in { xs => xs.groupBy(_ % 10) } using(ranges) in { xs => xs.groupBy(_ % 10) } } }
Automatic regression testing 
using(lists) in { xs => var sum = 0 xs.foreach(x => sum += x) }
Automatic regression testing 
using(lists) in { xs => var sum = 0 xs.foreach(x => sum += x) } 
[info] Test group: foreach [info] - foreach.Test-0 measurements: [info] - at size -> 2000000, 1 alternatives: passed [info] (ci = <7.28, 8.22>, significance = 1.0E-10)
Automatic regression testing 
using(lists) in { xs => var sum = 0 xs.foreach(x => sum += math.sqrt(x)) }
Automatic regression testing 
using(lists) in { xs => var sum = 0 xs.foreach(x => sum += math.sqrt(x)) } 
[info] Test group: foreach [info] - foreach.Test-0 measurements: [info] - at size -> 2000000, 2 alternatives: failed [info] (ci = <14.57, 15.38>, significance = 1.0E-10) [error] Failed confidence interval test: <-7.85, -6.60> [error] Previous (mean = 7.75, stdev = 0.44, ci = <7.28, 8.22>) [error] Latest (mean = 14.97, stdev = 0.38, ci = <14.57, 15.38>)
Automatic regression testing 
-configurable: ANOVA (analysis of variance) or confidence interval testing 
-can apply noise to make unstable tests more solid 
-various policies on keeping the result history
Report generation
Tutorials online! 
http://axel22.github.com/scalameter 
Questions?

More Related Content

What's hot

Bayesian Inference and Uncertainty Quantification for Inverse Problems
Bayesian Inference and Uncertainty Quantification for Inverse ProblemsBayesian Inference and Uncertainty Quantification for Inverse Problems
Bayesian Inference and Uncertainty Quantification for Inverse Problems
Matt Moores
 
Killing The Unit test talk
Killing The Unit test talkKilling The Unit test talk
Killing The Unit test talk
dor sever
 
Discrete control2 converted
Discrete control2 convertedDiscrete control2 converted
Discrete control2 converted
cairo university
 
Block diagrams
Block diagramsBlock diagrams
Block diagrams
lecturer in M.I.T
 
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
Matt Moores
 
R data mining-Time Series Analysis with R
R data mining-Time Series Analysis with RR data mining-Time Series Analysis with R
R data mining-Time Series Analysis with R
Dr. Volkan OBAN
 
MLE Example
MLE ExampleMLE Example
MLE Example
Edda Kang
 
Test s velocity_15_5_4
Test s velocity_15_5_4Test s velocity_15_5_4
Test s velocity_15_5_4
Kunihiko Saito
 
DSP 05 _ Sheet Five
DSP 05 _ Sheet FiveDSP 05 _ Sheet Five
DSP 05 _ Sheet Five
Amr E. Mohamed
 
Servo systems
Servo systemsServo systems
Servo systems
cairo university
 
Digital control book
Digital control bookDigital control book
Digital control book
cairo university
 
Numerical Methods Solving Linear Equations
Numerical Methods Solving Linear EquationsNumerical Methods Solving Linear Equations
Time series-mining-slides
Time series-mining-slidesTime series-mining-slides
Time series-mining-slides
Yanchang Zhao
 
An Introduction into Anomaly Detection Using CUSUM
An Introduction into Anomaly Detection Using CUSUMAn Introduction into Anomaly Detection Using CUSUM
An Introduction into Anomaly Detection Using CUSUM
Dominik Dahlem
 
6. Vectors – Data Frames
6. Vectors – Data Frames6. Vectors – Data Frames
6. Vectors – Data Frames
FAO
 
Test (S) on R
Test (S) on RTest (S) on R
Test (S) on R
Kunihiko Saito
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
Ahmad sohail Kakar
 
Control of Discrete-Time Piecewise Affine Probabilistic Systems using Reachab...
Control of Discrete-Time Piecewise Affine Probabilistic Systems using Reachab...Control of Discrete-Time Piecewise Affine Probabilistic Systems using Reachab...
Control of Discrete-Time Piecewise Affine Probabilistic Systems using Reachab...
Leo Asselborn
 
09 - Program verification
09 - Program verification09 - Program verification
09 - Program verification
Tudor Girba
 
Algorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical FileAlgorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical File
KushagraChadha1
 

What's hot (20)

Bayesian Inference and Uncertainty Quantification for Inverse Problems
Bayesian Inference and Uncertainty Quantification for Inverse ProblemsBayesian Inference and Uncertainty Quantification for Inverse Problems
Bayesian Inference and Uncertainty Quantification for Inverse Problems
 
Killing The Unit test talk
Killing The Unit test talkKilling The Unit test talk
Killing The Unit test talk
 
Discrete control2 converted
Discrete control2 convertedDiscrete control2 converted
Discrete control2 converted
 
Block diagrams
Block diagramsBlock diagrams
Block diagrams
 
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
 
R data mining-Time Series Analysis with R
R data mining-Time Series Analysis with RR data mining-Time Series Analysis with R
R data mining-Time Series Analysis with R
 
MLE Example
MLE ExampleMLE Example
MLE Example
 
Test s velocity_15_5_4
Test s velocity_15_5_4Test s velocity_15_5_4
Test s velocity_15_5_4
 
DSP 05 _ Sheet Five
DSP 05 _ Sheet FiveDSP 05 _ Sheet Five
DSP 05 _ Sheet Five
 
Servo systems
Servo systemsServo systems
Servo systems
 
Digital control book
Digital control bookDigital control book
Digital control book
 
Numerical Methods Solving Linear Equations
Numerical Methods Solving Linear EquationsNumerical Methods Solving Linear Equations
Numerical Methods Solving Linear Equations
 
Time series-mining-slides
Time series-mining-slidesTime series-mining-slides
Time series-mining-slides
 
An Introduction into Anomaly Detection Using CUSUM
An Introduction into Anomaly Detection Using CUSUMAn Introduction into Anomaly Detection Using CUSUM
An Introduction into Anomaly Detection Using CUSUM
 
6. Vectors – Data Frames
6. Vectors – Data Frames6. Vectors – Data Frames
6. Vectors – Data Frames
 
Test (S) on R
Test (S) on RTest (S) on R
Test (S) on R
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
 
Control of Discrete-Time Piecewise Affine Probabilistic Systems using Reachab...
Control of Discrete-Time Piecewise Affine Probabilistic Systems using Reachab...Control of Discrete-Time Piecewise Affine Probabilistic Systems using Reachab...
Control of Discrete-Time Piecewise Affine Probabilistic Systems using Reachab...
 
09 - Program verification
09 - Program verification09 - Program verification
09 - Program verification
 
Algorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical FileAlgorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical File
 

Similar to ScalaMeter 2012

ScalaMeter 2014
ScalaMeter 2014ScalaMeter 2014
ScalaMeter 2014
Aleksandar Prokopec
 
Mechanical Engineering Assignment Help
Mechanical Engineering Assignment HelpMechanical Engineering Assignment Help
Mechanical Engineering Assignment Help
Matlab Assignment Experts
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Dr. Volkan OBAN
 
TALLER PARCIAL II CÁLCULO 3246 (CASTRO,SALAZAR,SHIGUANGO)
TALLER PARCIAL II CÁLCULO 3246 (CASTRO,SALAZAR,SHIGUANGO)TALLER PARCIAL II CÁLCULO 3246 (CASTRO,SALAZAR,SHIGUANGO)
TALLER PARCIAL II CÁLCULO 3246 (CASTRO,SALAZAR,SHIGUANGO)
ChrysleerSalazar
 
Bb2
Bb2Bb2
Bb2
brehot2
 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88
Mahmoud Samir Fayed
 
Polyglot Persistence in the Real World: Cassandra + S3 + MapReduce
Polyglot Persistence in the Real World: Cassandra + S3 + MapReducePolyglot Persistence in the Real World: Cassandra + S3 + MapReduce
Polyglot Persistence in the Real World: Cassandra + S3 + MapReduce
thumbtacktech
 
Tues 115pm cassandra + s3 + hadoop = quick auditing and analytics_yazovskiy
Tues 115pm cassandra + s3 + hadoop = quick auditing and analytics_yazovskiyTues 115pm cassandra + s3 + hadoop = quick auditing and analytics_yazovskiy
Tues 115pm cassandra + s3 + hadoop = quick auditing and analytics_yazovskiy
Anton Yazovskiy
 
ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine
Aleksandar Prokopec
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2
Scilab
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
Python Homework Help
 
Longest Common Subsequence & Matrix Chain Multiplication
Longest Common Subsequence & Matrix Chain MultiplicationLongest Common Subsequence & Matrix Chain Multiplication
Longest Common Subsequence & Matrix Chain Multiplication
JaneAlamAdnan
 
Backpropagation - Elisa Sayrol - UPC Barcelona 2018
Backpropagation - Elisa Sayrol - UPC Barcelona 2018Backpropagation - Elisa Sayrol - UPC Barcelona 2018
Backpropagation - Elisa Sayrol - UPC Barcelona 2018
Universitat Politècnica de Catalunya
 
Design and Implementation of Parallel and Randomized Approximation Algorithms
Design and Implementation of Parallel and Randomized Approximation AlgorithmsDesign and Implementation of Parallel and Randomized Approximation Algorithms
Design and Implementation of Parallel and Randomized Approximation Algorithms
Ajay Bidyarthy
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
Manchireddy Reddy
 
Investigación de operaciones 026 programación lineal Solución Simplex con R S...
Investigación de operaciones 026 programación lineal Solución Simplex con R S...Investigación de operaciones 026 programación lineal Solución Simplex con R S...
Investigación de operaciones 026 programación lineal Solución Simplex con R S...
Jorge Pablo Rivas
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
kebeAman
 
A BA-based algorithm for parameter optimization of support vector machine
A BA-based algorithm for parameter optimization of support vector machineA BA-based algorithm for parameter optimization of support vector machine
A BA-based algorithm for parameter optimization of support vector machine
Aboul Ella Hassanien
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
Abd El Kareem Ahmed
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx
BeheraA
 

Similar to ScalaMeter 2012 (20)

ScalaMeter 2014
ScalaMeter 2014ScalaMeter 2014
ScalaMeter 2014
 
Mechanical Engineering Assignment Help
Mechanical Engineering Assignment HelpMechanical Engineering Assignment Help
Mechanical Engineering Assignment Help
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
 
TALLER PARCIAL II CÁLCULO 3246 (CASTRO,SALAZAR,SHIGUANGO)
TALLER PARCIAL II CÁLCULO 3246 (CASTRO,SALAZAR,SHIGUANGO)TALLER PARCIAL II CÁLCULO 3246 (CASTRO,SALAZAR,SHIGUANGO)
TALLER PARCIAL II CÁLCULO 3246 (CASTRO,SALAZAR,SHIGUANGO)
 
Bb2
Bb2Bb2
Bb2
 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88
 
Polyglot Persistence in the Real World: Cassandra + S3 + MapReduce
Polyglot Persistence in the Real World: Cassandra + S3 + MapReducePolyglot Persistence in the Real World: Cassandra + S3 + MapReduce
Polyglot Persistence in the Real World: Cassandra + S3 + MapReduce
 
Tues 115pm cassandra + s3 + hadoop = quick auditing and analytics_yazovskiy
Tues 115pm cassandra + s3 + hadoop = quick auditing and analytics_yazovskiyTues 115pm cassandra + s3 + hadoop = quick auditing and analytics_yazovskiy
Tues 115pm cassandra + s3 + hadoop = quick auditing and analytics_yazovskiy
 
ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Longest Common Subsequence & Matrix Chain Multiplication
Longest Common Subsequence & Matrix Chain MultiplicationLongest Common Subsequence & Matrix Chain Multiplication
Longest Common Subsequence & Matrix Chain Multiplication
 
Backpropagation - Elisa Sayrol - UPC Barcelona 2018
Backpropagation - Elisa Sayrol - UPC Barcelona 2018Backpropagation - Elisa Sayrol - UPC Barcelona 2018
Backpropagation - Elisa Sayrol - UPC Barcelona 2018
 
Design and Implementation of Parallel and Randomized Approximation Algorithms
Design and Implementation of Parallel and Randomized Approximation AlgorithmsDesign and Implementation of Parallel and Randomized Approximation Algorithms
Design and Implementation of Parallel and Randomized Approximation Algorithms
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Investigación de operaciones 026 programación lineal Solución Simplex con R S...
Investigación de operaciones 026 programación lineal Solución Simplex con R S...Investigación de operaciones 026 programación lineal Solución Simplex con R S...
Investigación de operaciones 026 programación lineal Solución Simplex con R S...
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
 
A BA-based algorithm for parameter optimization of support vector machine
A BA-based algorithm for parameter optimization of support vector machineA BA-based algorithm for parameter optimization of support vector machine
A BA-based algorithm for parameter optimization of support vector machine
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx
 

Recently uploaded

ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 

Recently uploaded (20)

ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 

ScalaMeter 2012

  • 1. ScalaMeter Performance regression testing framework Aleksandar Prokopec, Josh Suereth
  • 2. Goal List(1 to 100000: _*).map(x => x * x) 26 ms
  • 3. Goal List(1 to 100000: _*).map(x => x * x) class List[+T] extends Seq[T] { // implementation 1 } 26 ms
  • 4. Goal List(1 to 100000: _*).map(x => x * x) class List[+T] extends Seq[T] { // implementation 1 } 26 ms
  • 5. Goal List(1 to 100000: _*).map(x => x * x) class List[+T] extends Seq[T] { // implementation 2 } 49 ms
  • 6. First example def measure() { val buffer = mutable.ArrayBuffer(0 until 2000000: _*) val start = System.currentTimeMillis() var sum = 0 buffer.foreach(sum += _) val end = System.currentTimeMillis() println(end - start) }
  • 7. First example def measure() { val buffer = mutable.ArrayBuffer(0 until 2000000: _*) val start = System.currentTimeMillis() var sum = 0 buffer.foreach(sum += _) val end = System.currentTimeMillis() println(end - start) }
  • 8. First example def measure() { val buffer = mutable.ArrayBuffer(0 until 2000000: _*) val start = System.currentTimeMillis() var sum = 0 buffer.foreach(sum += _) val end = System.currentTimeMillis() println(end - start) }
  • 9. First example def measure() { val buffer = mutable.ArrayBuffer(0 until 2000000: _*) val start = System.currentTimeMillis() var sum = 0 buffer.foreach(sum += _) val end = System.currentTimeMillis() println(end - start) }
  • 10. First example def measure() { val buffer = mutable.ArrayBuffer(0 until 2000000: _*) val start = System.currentTimeMillis() var sum = 0 buffer.foreach(sum += _) val end = System.currentTimeMillis() println(end - start) } measure()
  • 11. First example def measure() { val buffer = mutable.ArrayBuffer(0 until 2000000: _*) val start = System.currentTimeMillis() var sum = 0 buffer.foreach(sum += _) val end = System.currentTimeMillis() println(end - start) } measure() 26 ms
  • 12. The warmup problem def measure() { val buffer = mutable.ArrayBuffer(0 until 2000000: _*) val start = System.currentTimeMillis() var sum = 0 buffer.foreach(sum += _) val end = System.currentTimeMillis() println(end - start) } measure() measure() 26 ms, 11 ms
  • 13. The warmup problem def measure() { val buffer = mutable.ArrayBuffer(0 until 2000000: _*) val start = System.currentTimeMillis() var sum = 0 buffer.foreach(sum += _) val end = System.currentTimeMillis() println(end - start) } measure() measure() 26 ms, 11 ms Why? Mainly: - JIT compilation - dynamic optimization
  • 14. The warmup problem def measure() { val buffer = mutable.ArrayBuffer(0 until 2000000: _*) val start = System.currentTimeMillis() var sum = 0 buffer.foreach(sum += _) val end = System.currentTimeMillis() println(end - start) } 45 ms, 10 ms 26 ms, 11 ms
  • 15. The warmup problem def measure2() { val buffer = mutable.ArrayBuffer(0 until 4000000: _*) val start = System.currentTimeMillis() buffer.map(_ + 1) val end = System.currentTimeMillis() println(end - start) }
  • 16. The warmup problem def measure2() { val buffer = mutable.ArrayBuffer(0 until 4000000: _*) val start = System.currentTimeMillis() buffer.map(_ + 1) val end = System.currentTimeMillis() println(end - start) } 241, 238, 235, 236, 234
  • 17. The warmup problem def measure2() { val buffer = mutable.ArrayBuffer(0 until 4000000: _*) val start = System.currentTimeMillis() buffer.map(_ + 1) val end = System.currentTimeMillis() println(end - start) } 241, 238, 235, 236, 234, 429
  • 18. The warmup problem def measure2() { val buffer = mutable.ArrayBuffer(0 until 4000000: _*) val start = System.currentTimeMillis() buffer.map(_ + 1) val end = System.currentTimeMillis() println(end - start) } 241, 238, 235, 236, 234, 429, 209
  • 19. The warmup problem def measure2() { val buffer = mutable.ArrayBuffer(0 until 4000000: _*) val start = System.currentTimeMillis() buffer.map(_ + 1) val end = System.currentTimeMillis() println(end - start) } 241, 238, 235, 236, 234, 429, 209, 194, 195, 195
  • 20. The warmup problem Bottomline: benchmark has to be repeated until the running time becomes “stable”. The number of repetitions is not known in advance. 241, 238, 235, 236, 234, 429, 209, 194, 195, 195
  • 21. Warming up the JVM 241, 238, 235, 236, 234, 429, 209, 194, 195, 195, 194, 194, 193, 194, 196, 195, 195 Can this be automated? Idea: measure variance of the running times. When it becomes sufficiently small, the test has stabilized.
  • 22. The interference problem val buffer = ArrayBuffer(0 until 900000: _*) buffer.map(_ + 1) val buffer = ListBuffer(0 until 900000: _*) buffer.map(_ + 1)
  • 23. The interference problem Lets measure the first map 3 times with 7 repetitions: val buffer = ArrayBuffer(0 until 900000: _*) buffer.map(_ + 1) val buffer = ListBuffer(0 until 900000: _*) buffer.map(_ + 1) 61, 54, 54, 54, 55, 55, 56 186, 54, 54, 54, 55, 54, 53 54, 54, 53, 53, 53, 54, 51
  • 24. The interference problem val buffer = ArrayBuffer(0 until 900000: _*) buffer.map(_ + 1) val buffer = ListBuffer(0 until 900000: _*) buffer.map(_ + 1) Now, lets measure the list buffer map in between: 61, 54, 54, 54, 55, 55, 56 186, 54, 54, 54, 55, 54, 53 54, 54, 53, 53, 53, 54, 51 59, 54, 54, 54, 54, 54, 54 44, 36, 36, 36, 35, 36, 36 45, 45, 45, 45, 44, 46, 45 18, 17, 18, 18, 17, 292, 16 45, 45, 44, 44, 45, 45, 44
  • 25. The interference problem val buffer = ArrayBuffer(0 until 900000: _*) buffer.map(_ + 1) val buffer = ListBuffer(0 until 900000: _*) buffer.map(_ + 1) Now, lets measure the list buffer map in between: 61, 54, 54, 54, 55, 55, 56 186, 54, 54, 54, 55, 54, 53 54, 54, 53, 53, 53, 54, 51 59, 54, 54, 54, 54, 54, 54 44, 36, 36, 36, 35, 36, 36 45, 45, 45, 45, 44, 46, 45 18, 17, 18, 18, 17, 292, 16 45, 45, 44, 44, 45, 45, 44
  • 26. Using separate JVM Bottomline: always run the tests in a new JVM.
  • 27. Using separate JVM Bottomline: always run the tests in a new JVM. This may not reflect a real-world scenario, but it gives a good idea of how different several alternatives are.
  • 28. Using separate JVM Bottomline: always run the tests in a new JVM. It results in a reproducible, more stable measurement.
  • 29. The List.map example val list = (0 until 2500000).toList list.map(_ % 2 == 0)
  • 30. The List.map example val list = (0 until 2500000).toList list.map(_ % 2 == 0) 37, 38, 37, 1175, 38, 37, 37, 37, 37, …, 38, 37, 37, 37, 37, 465, 35, 35, …
  • 31. The garbage collection problem val list = (0 until 2500000).toList list.map(_ % 2 == 0) 37, 38, 37, 1175, 38, 37, 37, 37, 37, …, 38, 37, 37, 37, 37, 465, 35, 35, … This benchmark triggers GC cycles!
  • 32. The garbage collection problem val list = (0 until 2500000).toList list.map(_ % 2 == 0) 37, 38, 37, 1175, 38, 37, 37, 37, 37, …, 38, 37, 37, 37, 37, 465, 35, 35, … -> mean: 47 ms This benchmark triggers GC cycles!
  • 33. The garbage collection problem val list = (0 until 2500000).toList list.map(_ % 2 == 0) 37, 38, 37, 1175, 38, 37, 37, 37, 37, …, 38, 37, 37, 37, 37, 465, 35, 35, … -> mean: 47 ms This benchmark triggers GC cycles! 37, 37, 37, 647, 37, 36, 38, 37, 36, …, 36, 37, 36, 37, 36, 37, 534, 36, 33, … -> mean: 39 ms
  • 34. The garbage collection problem val list = (0 until 2500000).toList list.map(_ % 2 == 0) 37, 38, 37, 1175, 38, 37, 37, 37, 37, …, 38, 37, 37, 37, 37, 465, 35, 35, … -> mean: 47 ms This benchmark triggers GC cycles! 37, 37, 37, 647, 37, 36, 38, 37, 36, …, 36, 37, 36, 37, 36, 37, 534, 36, 33, … -> mean: 39 ms
  • 35. The garbage collection problem val list = (0 until 2500000).toList list.map(_ % 2 == 0) Solutions: -repeat A LOT of times –an accurate mean, but takes A LONG time
  • 36. The garbage collection problem val list = (0 until 2500000).toList list.map(_ % 2 == 0) Solutions: -repeat A LOT of times –an accurate mean, but takes A LONG time -ignore the measurements with GC – gives a reproducible value, and less measurements
  • 37. The garbage collection problem val list = (0 until 2500000).toList list.map(_ % 2 == 0) Solutions: -repeat A LOT of times –an accurate mean, but takes A LONG time -ignore the measurements with GC – gives a reproducible value, and less measurements -how to do this?
  • 38. The garbage collection problem val list = (0 until 2500000).toList list.map(_ % 2 == 0) -manually - verbose:gc
  • 39. Automatic GC detection val list = (0 until 2500000).toList list.map(_ % 2 == 0) -manually - verbose:gc -automatically using callbacks in JDK7 37, 37, 37, 647, 37, 36, 38, 37, 36, …, 36, 37, 36, 37, 36, 37, 534, 36, 33, …
  • 40. Automatic GC detection val list = (0 until 2500000).toList list.map(_ % 2 == 0) -manually - verbose:gc -automatically using callbacks in JDK7 37, 37, 37, 647, 37, 36, 38, 37, 36, …, 36, 37, 36, 37, 36, 37, 534, 36, 33, … raises a GC event
  • 41. The runtime problem -there are other runtime events beside GC – e.g. JIT compilation, dynamic optimization, etc. -these take time, but cannot be determined accurately
  • 42. The runtime problem -there are other runtime events beside GC – e.g. JIT compilation, dynamic optimization, etc. -these take time, but cannot be determined accurately -heap state also influences memory allocation patterns and performance
  • 43. The runtime problem -there are other runtime events beside GC – e.g. JIT compilation, dynamic optimization, etc. -these take time, but cannot be determined accurately -heap state also influences memory allocation patterns and performance val list = (0 until 4000000).toList list.groupBy(_ % 10) (allocation intensive)
  • 44. The runtime problem -there are other runtime events beside GC – e.g. JIT compilation, dynamic optimization, etc. -these take time, but cannot be determined accurately -heap state also influences memory allocation patterns and performance val list = (0 until 4000000).toList list.groupBy(_ % 10) 120, 121, 122, 118, 123, 794, 109, 111, 115, 113, 110
  • 45. The runtime problem -there are other runtime events beside GC – e.g. JIT compilation, dynamic optimization, etc. -these take time, but cannot be determined accurately -heap state also influences memory allocation patterns and performance val list = (0 until 4000000).toList list.groupBy(_ % 10) 120, 121, 122, 118, 123, 794, 109, 111, 115, 113, 110 affects the mean – 116 ms vs 178 ms
  • 46. Outlier elimination 120, 121, 122, 118, 123, 794, 109, 111, 115, 113, 110
  • 47. Outlier elimination 120, 121, 122, 118, 123, 794, 109, 111, 115, 113, 110 109, 110, 111, 113, 115, 118, 120, 121, 122, 123, 794 sort
  • 48. Outlier elimination 120, 121, 122, 118, 123, 794, 109, 111, 115, 113, 110 109, 110, 111, 113, 115, 118, 120, 121, 122, 123, 794 sort inspect tail and its variance contribution 109, 110, 111, 113, 115, 118, 120, 121, 122, 123
  • 49. Outlier elimination 120, 121, 122, 118, 123, 794, 109, 111, 115, 113, 110 109, 110, 111, 113, 115, 118, 120, 121, 122, 123, 794 sort inspect tail and its variance contribution 109, 110, 111, 113, 115, 118, 120, 121, 122, 123 109, 110, 111, 113, 115, 118, 120, 121, 122, 123, 124 redo the measurement
  • 50. Doing all this manually
  • 51. ScalaMeter Does all this analysis automatically, highly configurable. Plus, it detects performance regressions. And generates reports.
  • 52. ScalaMeter example object ListTest extends PerformanceTest.Microbenchmark { A range of predefined benchmark types
  • 53. ScalaMeter example object ListTest extends PerformanceTest.Microbenchmark { val sizes = Gen.range("size”)(500000, 1000000, 100000) Generators provide input data for tests
  • 54. ScalaMeter example object ListTest extends PerformanceTest.Microbenchmark { val sizes = Gen.range("size”)(500000, 1000000, 100000) val lists = for (sz <- sizes) yield (0 until sz).toList Generators can be composed a la ScalaCheck
  • 55. ScalaMeter example object ListTest extends PerformanceTest.Microbenchmark { val sizes = Gen.range("size”)(500000, 1000000, 100000) val lists = for (sz <- sizes) yield (0 until sz).toList using(lists) in { xs => xs.groupBy(_ % 10) } } Concise syntax to specify and group tests
  • 56. ScalaMeter example object ListTest extends PerformanceTest.Microbenchmark { val sizes = Gen.range("size”)(500000, 1000000, 100000) val lists = for (sz <- sizes) yield (0 until sz).toList measure method “groupBy” in { using(lists) in { xs => xs.groupBy(_ % 10) } using(ranges) in { xs => xs.groupBy(_ % 10) } } }
  • 57. Automatic regression testing using(lists) in { xs => var sum = 0 xs.foreach(x => sum += x) }
  • 58. Automatic regression testing using(lists) in { xs => var sum = 0 xs.foreach(x => sum += x) } [info] Test group: foreach [info] - foreach.Test-0 measurements: [info] - at size -> 2000000, 1 alternatives: passed [info] (ci = <7.28, 8.22>, significance = 1.0E-10)
  • 59. Automatic regression testing using(lists) in { xs => var sum = 0 xs.foreach(x => sum += math.sqrt(x)) }
  • 60. Automatic regression testing using(lists) in { xs => var sum = 0 xs.foreach(x => sum += math.sqrt(x)) } [info] Test group: foreach [info] - foreach.Test-0 measurements: [info] - at size -> 2000000, 2 alternatives: failed [info] (ci = <14.57, 15.38>, significance = 1.0E-10) [error] Failed confidence interval test: <-7.85, -6.60> [error] Previous (mean = 7.75, stdev = 0.44, ci = <7.28, 8.22>) [error] Latest (mean = 14.97, stdev = 0.38, ci = <14.57, 15.38>)
  • 61. Automatic regression testing -configurable: ANOVA (analysis of variance) or confidence interval testing -can apply noise to make unstable tests more solid -various policies on keeping the result history