Benchmarks: write in Scala or JS, run in your browser. Live demo:
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
benchmark Upgrade most deps Dec 3, 2018
bin Seperate demo builds Nov 11, 2016
demo Upgrade Scalaz & Cats Nov 1, 2017
doc/changelog Upgrade most deps Dec 3, 2018
project Upgrade most deps Dec 3, 2018
.gitignore .gitignore Nov 13, 2015
.travis.yml Upgrade most deps Dec 3, 2018
LICENCE Time to do this for real Nov 18, 2015
README.md update ver in docs Dec 3, 2018
build.sbt create version.sbt Nov 5, 2017
params.gv omfg Nov 18, 2015
params.gv.svg omfg Nov 18, 2015
sampledata.ods Reconfigure default options Nov 21, 2015
version.sbt Setting version to 0.2.7-SNAPSHOT Dec 3, 2018

README.md

scalajs-benchmark

Build Status

Benchmarks: write in Scala or JS, run in your browser.

See an online demo here: https://japgolly.github.io/scalajs-benchmark/.
The tiny source code is here: gh-pages/demo.

ChangelogsLatest: 0.2.6.

How do I use it?

  1. Include scalajs-benchmark as a dependency in your Scala.JS project.
libraryDependencies += "com.github.japgolly.scalajs-benchmark" %%% "benchmark" % "0.2.6"
  1. You write benchmarks.
import japgolly.scalajs.benchmark._, gui._

object Example {
  val suite = GuiSuite(
    Suite("Example Benchmarks")(

      // Benchmark #1
      Benchmark("foreach") {
        var s = Set.empty[Int]
        (1 to 100) foreach (s += _)
        s
      },

      // Benchmark #2
      Benchmark("fold") {
        (1 to 100).foldLeft(Set.empty[Int])(_ + _)
      }
    )
  )
}

(Hey, can you make that 1 to 100 configurable in the GUI? You sure can.)

  1. Add a tiny loader HTML like this.

  2. Create a JSApp and point scalajs-benchmark at your suite of benchmarks.

import org.scalajs.dom.document
import japgolly.scalajs.benchmark.gui.BenchmarkGUI

object Main extends scalajs.js.JSApp {

  def main() = {
    val body = document getElementById "body"
    BenchmarkGUI.renderSuite(body)(Example.suite)
  }
}

If you have a library of different benchmarks, instead of using renderSuite, you use renderMenu to create an app that lets the user navigate the library and run benchmarks.

Example:

BenchmarkGUI.renderMenu(body)(
  suites.example.Examples.all,
  suites.scala.all)
  1. Compile; run in browser. Done.

Support

If you like what I do —my OSS libraries, my contributions to other OSS libs, my programming blog— and you'd like to support me, more content, more lib maintenance, please become a patron! I do all my OSS work unpaid so showing your support will make a big difference.


Note: This is not affiliated with the official Scala.JS project; it's just named to be informative rather than interesting.