DISCLAIMER. This project is guaranteed to work corrrectly only with SBT >0.11.2 (which is currently under development).
Starting from SBT >0.11.2, javaOptions
is a Task, rather than a Setting, which is essential for running benchmarks in
a forked process with correct classpath.
This is an XSBT template project for creating micro benchmarks for scala code snippets. It's not much more than a simple wrapper around Caliper, an open-source library for properly running benchmark code on the JVM (written by some guys at Google).
Manually writing benchmarks for the JVM that actually measure what you intend to measure is much harder than it initially appears. There are quite a few rules you need to keep in mind, so it's best to rely on a framework that takes care of the details and let's you focus on the code relevant to your application. Caliper provides just this framework and this project makes it easily accessible for Scala developers.
-
Git-clone this repository:
$ git clone [email protected]:remeniuk/scala-benchmarking-template.git my-benchmark
-
Change directory into your clone:
$ cd my-benchmark
-
Launch XSBT:
$ xsbt
-
Get dependencies:
> update
-
Run the existing benchmark:
> run
-
Start hacking on
src/main/scala/org/example/Benchmark.scala
As a simple example the project already contains a small benchmark testing the performance of foreach
ing over a
Scala Array
against a simple while
loop as well as a specialized, custom for
loop replacement implementation.
In order to run your own benchmark code simply replace the respectively marked code snippets with your own.