about summary refs log tree commit diff
path: root/third_party/immer/tools/scala
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/immer/tools/scala')
-rw-r--r--third_party/immer/tools/scala/README.md6
-rw-r--r--third_party/immer/tools/scala/build.sbt27
-rw-r--r--third_party/immer/tools/scala/src/test/scala/org/immer/benchmarks.scala168
-rw-r--r--third_party/immer/tools/scala/version.sbt1
4 files changed, 202 insertions, 0 deletions
diff --git a/third_party/immer/tools/scala/README.md b/third_party/immer/tools/scala/README.md
new file mode 100644
index 000000000000..ce514e445e99
--- /dev/null
+++ b/third_party/immer/tools/scala/README.md
@@ -0,0 +1,6 @@
+
+```
+# sbt
+> test
+> test-only org.immer.* -- -verbose
+```
diff --git a/third_party/immer/tools/scala/build.sbt b/third_party/immer/tools/scala/build.sbt
new file mode 100644
index 000000000000..f2d0bd2cf03c
--- /dev/null
+++ b/third_party/immer/tools/scala/build.sbt
@@ -0,0 +1,27 @@
+/**  This is the simplest possible use of ScalaMeter.
+  *  It allows running ScalaMeter benchmarks as part of the test suite.
+  *  It means, that when the test command is run, ScalaMeter benchmarks are run along
+  *  the tests from other test frameworks, such as ScalaTest or ScalaCheck.
+  */
+lazy val basic = Project(
+  "basic",
+  file("."),
+  settings = Defaults.coreDefaultSettings ++ Seq(
+    name := "immer-bechmarks",
+    organization := "org.immer",
+    scalaVersion := "2.11.1",
+    scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-Xlint"),
+    publishArtifact := false,
+    libraryDependencies ++= Seq(
+      "com.storm-enroute" %% "scalameter" % "0.8.2" % "test",
+      "io.github.nicolasstucki" %% "scala-rrb-vector" % "0.1.1"
+    ),
+    resolvers ++= Seq(
+      "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
+      "Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases"
+    ),
+    testFrameworks += new TestFramework("org.scalameter.ScalaMeterFramework"),
+    parallelExecution in Test := false,
+    logBuffered := false
+  )
+)
diff --git a/third_party/immer/tools/scala/src/test/scala/org/immer/benchmarks.scala b/third_party/immer/tools/scala/src/test/scala/org/immer/benchmarks.scala
new file mode 100644
index 000000000000..98c40a45cd66
--- /dev/null
+++ b/third_party/immer/tools/scala/src/test/scala/org/immer/benchmarks.scala
@@ -0,0 +1,168 @@
+package org.immer
+
+import org.scalameter.api._
+import scala.collection.immutable.Vector
+import scala.collection.immutable.rrbvector.RRBVector
+
+class BenchmarkBase extends Bench.ForkedTime {
+  val runs = 20
+  val size = 1000
+  val step = 10
+  val sizes = Gen.range("size")(size, size, 1)
+
+  //def relaxedV(v : RRBVector[Int], n : Int) : RRBVector[Int] = {
+  //  var r = v
+  //  for (i <- 0 to n) {
+  //    r = (RRBVector.empty[Int] :+ i) ++ r
+  //  }
+  //  r
+  //}
+
+  var vectors     = for { s <- sizes } yield Vector.empty[Int] ++ (0 until s)
+  var rrbvectors  = for { s <- sizes } yield RRBVector.empty[Int] ++ (0 until s)
+  //var rrbvectorsF = for { s <- sizes } yield relaxedV(RRBVector.empty[Int], s)
+  var rrbsteps    = for { s <- sizes } yield RRBVector.empty[Int] ++ (0 until s / step)
+}
+
+class PushBenchmark extends BenchmarkBase {
+  performance of "push" in {
+    measure method "Vector" in { using(sizes) config(exec.benchRuns -> runs) in { s => {
+      var v = Vector.empty[Int]
+      for (a <- 0 to s) {
+        v = v :+ a
+      }
+      v
+    }}}
+    measure method "RRBVector" in { using(sizes) config(exec.benchRuns -> runs) in { s => {
+      var v = RRBVector.empty[Int]
+      for (a <- 0 to s) {
+        v = v :+ a
+      }
+      v
+    }}}
+  }
+}
+
+class UpdateBenchmark extends BenchmarkBase {
+  performance of "update" in {
+    measure method "Vector" in { using(vectors) config(exec.benchRuns -> runs) in { v0 => {
+      var v = v0
+      for (a <- 0 to v.size - 1) {
+        v = v.updated(a, a + 1)
+      }
+      v
+    }}}
+    measure method "RRBVector" in { using(rrbvectors) config(exec.benchRuns -> runs) in { v0 => {
+      var v = v0
+      for (a <- 0 to v.size - 1) {
+        v = v.updated(a, a + 1)
+      }
+      v
+    }}}
+    //measure method "RRBVector/relaxed" in { using(rrbvectorsF) config(exec.benchRuns -> runs) in { v0 => {
+    //  var v = v0
+    //  for (a <- 0 to v.size - 1) {
+    //    v = v.updated(a, a + 1)
+    //  }
+    //  v
+    //}}}
+  }
+  performance of "update/random" in {
+    measure method "Vector" in { using(vectors) config(exec.benchRuns -> runs) in { v0 => {
+      var v = v0
+      var r = new scala.util.Random
+      for (a <- 0 to v.size - 1) {
+        v = v.updated(r.nextInt(v.size), a + 1)
+      }
+      v
+    }}}
+    measure method "RRBVector" in { using(rrbvectors) config(exec.benchRuns -> runs) in { v0 => {
+      var v = v0
+      var r = new scala.util.Random
+      for (a <- 0 to v.size - 1) {
+        v = v.updated(r.nextInt(v.size), a + 1)
+      }
+      v
+    }}}
+    //measure method "RRBVector/relaxed" in { using(rrbvectorsF) config(exec.benchRuns -> runs) in { v0 => {
+    //  var v = v0
+    //  var r = new scala.util.Random
+    //  for (a <- 0 to v.size - 1) {
+    //    v = v.updated(r.nextInt(v.size), a + 1)
+    //  }
+    //  v
+    //}}}
+  }
+}
+
+object IterBenchmark extends BenchmarkBase {
+  performance of "access/reduce" in {
+    measure method "Vector" in { using(vectors) config(exec.benchRuns -> runs) in { v => {
+      v.reduceLeft(_ + _)
+    }}}
+    measure method "RRBVector" in { using(rrbvectors) config(exec.benchRuns -> runs) in { v => {
+      v.reduceLeft(_ + _)
+    }}}
+    //measure method "RRBVector/relaxed" in { using(rrbvectorsF) config(exec.benchRuns -> runs) in { v => {
+    //  v.reduceLeft(_ + _)
+    //}}}
+  }
+  performance of "access/idx" in {
+    measure method "Vector" in { using(vectors) config(exec.benchRuns -> runs) in { v => {
+      var r = 0
+      for (a <- 0 to v.size - 1) {
+        r += v(a)
+      }
+      r
+    }}}
+    measure method "RRBVector" in { using(rrbvectors) config(exec.benchRuns -> runs) in { v => {
+      var r = 0
+      for (a <- 0 to v.size - 1) {
+        r += v(a)
+      }
+      r
+    }}}
+    //measure method "RRBVector/relaxed" in { using(rrbvectorsF) config(exec.benchRuns -> runs) in { v => {
+    //  var r = 0
+    //  for (a <- 0 to v.size - 1) {
+    //    r += v(a)
+    //  }
+    //  r
+    //}}}
+  }
+  performance of "access/iter" in {
+    measure method "Vector" in { using(vectors) config(exec.benchRuns -> runs) in { v => {
+      var r = 0
+      for (a <- v) {
+        r += a
+      }
+      r
+    }}}
+    measure method "RRBVector" in { using(rrbvectors) config(exec.benchRuns -> runs) in { v => {
+      var r = 0
+      for (a <- v) {
+        r += a
+      }
+      r
+    }}}
+    //measure method "RRBVector/relaxed" in { using(rrbvectorsF) config(exec.benchRuns -> runs) in { v => {
+    //  var r = 0
+    //  for (a <- v) {
+    //    r += a
+    //  }
+    //  r
+    //}}}
+  }
+}
+
+class ConcatBenchmark extends BenchmarkBase {
+  performance of "concat" in {
+    measure method "RRBVector ++" in { using(rrbsteps) config(exec.benchRuns -> runs) in { v => {
+      var r = RRBVector.empty[Int]
+      for (_ <- 0 to step) {
+        r = r ++ v
+      }
+      r
+    }}}
+  }
+}
diff --git a/third_party/immer/tools/scala/version.sbt b/third_party/immer/tools/scala/version.sbt
new file mode 100644
index 000000000000..3f0ac089016a
--- /dev/null
+++ b/third_party/immer/tools/scala/version.sbt
@@ -0,0 +1 @@
+version in ThisBuild := "0.8.2"