Skip to content

Instantly share code, notes, and snippets.

@tixxit
Last active August 29, 2015 14:15
Show Gist options
  • Save tixxit/e80586e62c50bffbdfdb to your computer and use it in GitHub Desktop.
Save tixxit/e80586e62c50bffbdfdb to your computer and use it in GitHub Desktop.
Benchmark Mode Samples Score Error Units
a.b.TupleMatchBenchmark.emptyListLeft2Match thrpt 10 253467840.436 ± 12223892.822 ops/s
a.b.TupleMatchBenchmark.emptyListLeft2MatchFast thrpt 10 323188324.807 ± 13942236.297 ops/s
a.b.TupleMatchBenchmark.emptyListLeft2MatchFaster thrpt 10 308222316.257 ± 17156861.142 ops/s
a.b.TupleMatchBenchmark.emptyListLeftTuple thrpt 10 290671450.799 ± 15305844.711 ops/s
a.b.TupleMatchBenchmark.emptyListLeftTupleHeap thrpt 10 162238249.825 ± 5178063.946 ops/s
a.b.TupleMatchBenchmark.emptyListRight2Match thrpt 10 220221734.727 ± 3555704.452 ops/s
a.b.TupleMatchBenchmark.emptyListRight2MatchFast thrpt 10 236875354.510 ± 4604759.625 ops/s
a.b.TupleMatchBenchmark.emptyListRight2MatchFaster thrpt 10 332236731.746 ± 4843149.704 ops/s
a.b.TupleMatchBenchmark.emptyListRightTuple thrpt 10 305556965.402 ± 3343750.517 ops/s
a.b.TupleMatchBenchmark.emptyListRightTupleHeap thrpt 10 162082837.550 ± 7015805.533 ops/s
a.b.TupleMatchBenchmark.emptyLists2Match thrpt 10 403974677.391 ± 3741407.088 ops/s
a.b.TupleMatchBenchmark.emptyLists2MatchFast thrpt 10 374838359.717 ± 20196373.923 ops/s
a.b.TupleMatchBenchmark.emptyLists2MatchFaster thrpt 10 382551994.617 ± 19779196.751 ops/s
a.b.TupleMatchBenchmark.emptyListsTuple thrpt 10 383050848.374 ± 24689381.633 ops/s
a.b.TupleMatchBenchmark.emptyListsTupleHeap thrpt 10 156116575.641 ± 10240649.596 ops/s
a.b.TupleMatchBenchmark.nonEmptyLists2Match thrpt 10 204851392.131 ± 13503321.337 ops/s
a.b.TupleMatchBenchmark.nonEmptyLists2MatchFast thrpt 10 199059823.003 ± 15640454.931 ops/s
a.b.TupleMatchBenchmark.nonEmptyLists2MatchFaster thrpt 10 209463692.158 ± 12135568.592 ops/s
a.b.TupleMatchBenchmark.nonEmptyListsTuple thrpt 10 203637089.638 ± 5339662.574 ops/s
a.b.TupleMatchBenchmark.nonEmptyListsTupleHeap thrpt 10 126132252.642 ± 4469449.502 ops/s
package algebra.benchmark
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Param
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.Setup
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.annotations.{ Fork, Warmup, Measurement }
@Warmup(iterations = 5)
@Measurement(iterations = 10)
@Fork(1)
@State(Scope.Thread)
class TupleMatchBenchmark {
val xs: List[Int] = List(1,2,3)
val ys: List[Int] = List(4,5,6)
val empty: List[Int] = Nil
var tpl: (List[Int], List[Int]) = _
private def checkTupleHeap(as: List[Int], bs: List[Int]): Int = {
tpl = (as, bs)
tpl match {
case (Nil, Nil) => 0
case (Nil, _) => -1
case (_, Nil) => 1
case (x :: _, y :: _) => x - y
}
}
private def checkTuple(as: List[Int], bs: List[Int]): Int =
(as, bs) match {
case (Nil, Nil) => 0
case (Nil, _) => -1
case (_, Nil) => 1
case (x :: _, y :: _) => x - y
}
private def check2Match(as: List[Int], bs: List[Int]): Int =
as match {
case Nil =>
bs match {
case Nil => 0
case _ => -1
}
case (x :: _) =>
bs match {
case Nil => 1
case (y :: _) => x - y
}
}
private def check2MatchFast(as: List[Int], bs: List[Int]): Int =
as match {
case Nil =>
if (bs.isEmpty) 0 else -1
case (x :: _) =>
bs match {
case Nil => 1
case (y :: _) => x - y
}
}
private def check2MatchFaster(as: List[Int], bs: List[Int]): Int =
if (as.isEmpty) {
if (bs.isEmpty) 0 else -1
} else if (bs.isEmpty) {
1
} else {
as.head - bs.head
}
@Benchmark
def nonEmptyListsTupleHeap: Int = checkTupleHeap(xs, ys)
@Benchmark
def emptyListLeftTupleHeap: Int = checkTupleHeap(empty, ys)
@Benchmark
def emptyListRightTupleHeap: Int = checkTupleHeap(xs, empty)
@Benchmark
def emptyListsTupleHeap: Int = checkTupleHeap(empty, empty)
@Benchmark
def nonEmptyListsTuple: Int = checkTuple(xs, ys)
@Benchmark
def emptyListLeftTuple: Int = checkTuple(empty, ys)
@Benchmark
def emptyListRightTuple: Int = checkTuple(xs, empty)
@Benchmark
def emptyListsTuple: Int = checkTuple(empty, empty)
@Benchmark
def nonEmptyLists2Match: Int = check2Match(xs, ys)
@Benchmark
def emptyListLeft2Match: Int = check2Match(empty, ys)
@Benchmark
def emptyListRight2Match: Int = check2Match(xs, empty)
@Benchmark
def emptyLists2Match: Int = check2Match(empty, empty)
@Benchmark
def nonEmptyLists2MatchFast: Int = check2MatchFast(xs, ys)
@Benchmark
def emptyListLeft2MatchFast: Int = check2MatchFast(empty, ys)
@Benchmark
def emptyListRight2MatchFast: Int = check2MatchFast(xs, empty)
@Benchmark
def emptyLists2MatchFast: Int = check2MatchFast(empty, empty)
@Benchmark
def nonEmptyLists2MatchFaster: Int = check2MatchFaster(xs, ys)
@Benchmark
def emptyListLeft2MatchFaster: Int = check2MatchFaster(empty, ys)
@Benchmark
def emptyListRight2MatchFaster: Int = check2MatchFaster(xs, empty)
@Benchmark
def emptyLists2MatchFaster: Int = check2MatchFaster(empty, empty)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment