diff options
author | Vincent Ambo <mail@tazj.in> | 2020-07-15T07·20+0100 |
---|---|---|
committer | Vincent Ambo <mail@tazj.in> | 2020-07-15T07·23+0100 |
commit | 1213b086a1015a662ab7ebd658f784534fd3116a (patch) | |
tree | d3bc8f3b7f40b8b60f0ef6fbd649cf765f4fdfb6 /third_party/immer/tools/scala/src | |
parent | 1390827b9ea1e04bc9863e48930bfd16db3b716e (diff) | |
parent | 7f19d641647ac4ef313ed88d6b5c140983ce5436 (diff) |
merge(3p/immer): Subtree merge at 'ad3e3556d' as 'third_party/immer' r/1299
Change-Id: I9636a41ad44b4218293833fd3e9456d9b07c731b
Diffstat (limited to 'third_party/immer/tools/scala/src')
-rw-r--r-- | third_party/immer/tools/scala/src/test/scala/org/immer/benchmarks.scala | 168 |
1 files changed, 168 insertions, 0 deletions
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 + }}} + } +} |