Skip to content

Commit 8184980

Browse files
author
Antoine Brunner
committed
Made benchmarks more consistent and complete
1 parent c3ded4f commit 8184980

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

bench-run/src/main/scala/tuples/Apply.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ class Apply {
2121
}
2222

2323
@Benchmark
24-
def baseline(): Unit = {}
25-
26-
@Benchmark
27-
def normal(): Any = {
28-
tuple(index)
24+
def tupleApply(): Any = {
25+
DynamicTuple.dynamicApply(tuple, index)
2926
}
3027

3128
@Benchmark
32-
def inlined(): Any = {
33-
DynamicTuple.dynamicApply(tuple, index)
29+
def productElement(): Any = {
30+
tuple.asInstanceOf[Product].productElement(index)
3431
}
3532
}

bench-run/src/main/scala/tuples/ArrayOps.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,27 @@ class ArrayOps {
2323
}
2424

2525
@Benchmark
26-
def baseline(): Unit = {}
27-
28-
@Benchmark
29-
def toArray(): Array[Object] = {
26+
def tupleToArray(): Array[Object] = {
3027
DynamicTuple.dynamicToArray(tuple)
3128
}
3229

3330
@Benchmark
34-
def toIArray(): IArray[Object] = {
31+
def tupleToIArray(): IArray[Object] = {
3532
DynamicTuple.dynamicToIArray(tuple)
3633
}
3734

3835
@Benchmark
39-
def fromArray(): Tuple = {
36+
def tupleFromArray(): Tuple = {
4037
DynamicTuple.dynamicFromArray(array)
4138
}
4239

4340
@Benchmark
44-
def fromIArray(): Tuple = {
41+
def tupleFromIArray(): Tuple = {
4542
DynamicTuple.dynamicFromIArray(iarray)
4643
}
44+
45+
@Benchmark
46+
def productToArray(): Array[Object] = {
47+
DynamicTuple.productToArray(tuple.asInstanceOf[Product])
48+
}
4749
}

bench-run/src/main/scala/tuples/Concat.scala

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,12 @@ class Concat {
3131
}
3232

3333
@Benchmark
34-
def baseline(): Unit = {}
35-
36-
@Benchmark
37-
def normal(): Tuple = {
38-
tuple1 ++ tuple2
39-
}
40-
41-
@Benchmark
42-
def inlined(): Tuple = {
34+
def tupleConcat(): Tuple = {
4335
DynamicTuple.dynamicConcat(tuple1, tuple2)
4436
}
4537

46-
// This part is here to try and measure the overhead of tranforming tuples to arrays, then concatenating
47-
// the array, and then transforming back to a tuple
48-
@Benchmark
49-
def toArray(bh: Blackhole): Unit = {
50-
bh.consume(DynamicTuple.dynamicToArray(tuple1))
51-
bh.consume(DynamicTuple.dynamicToArray(tuple2))
52-
}
53-
5438
@Benchmark
5539
def arrayConcat(): Array[Object] = {
5640
array1 ++ array2
5741
}
58-
59-
@Benchmark
60-
def fromArray(bh: Blackhole): Unit = {
61-
bh.consume(DynamicTuple.dynamicFromArray[Tuple](array1))
62-
bh.consume(DynamicTuple.dynamicFromArray[Tuple](array2))
63-
}
6442
}

bench-run/src/main/scala/tuples/Cons.scala

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,10 @@ class Cons {
2121
}
2222

2323
@Benchmark
24-
def baseline(): Unit = {}
25-
26-
@Benchmark
27-
def normal(): Tuple = {
28-
"elem" *: tuple
29-
}
30-
31-
@Benchmark
32-
def inlined(): Tuple = {
24+
def tupleCons(): Tuple = {
3325
DynamicTuple.dynamicCons("elem", tuple)
3426
}
3527

36-
// This part is here to measure the performance of dong a cons on arrays directly
3728
@Benchmark
3829
def arrayCons(): Array[Object] = {
3930
DynamicTuple.cons$Array("elem", array)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dotty.tools.benchmarks.tuples
2+
3+
import org.openjdk.jmh.annotations._
4+
import scala.runtime.DynamicTuple
5+
6+
@State(Scope.Thread)
7+
class Tail {
8+
@Param(Array("1"))
9+
var size: Int = _
10+
var tuple: NonEmptyTuple = _
11+
var array: Array[Object] = _
12+
13+
@Setup
14+
def setup(): Unit = {
15+
tuple = "elem" *: ()
16+
17+
for (i <- 1 until size)
18+
tuple = "elem" *: tuple
19+
20+
array = Array.fill(size)("elem")
21+
}
22+
23+
@Benchmark
24+
def tupleTail(): Tuple = {
25+
DynamicTuple.dynamicTail(tuple)
26+
}
27+
28+
@Benchmark
29+
def arrayTail(): Array[Object] = {
30+
array.tail
31+
}
32+
}

0 commit comments

Comments
 (0)