Skip to content

Commit 0cdf81e

Browse files
author
Antoine Brunner
committed
Create detailed benchmarks about tuples
1 parent 62a0c28 commit 0cdf81e

File tree

5 files changed

+91
-3
lines changed

5 files changed

+91
-3
lines changed

bench-run/outputs/concat.csv

Whitespace-only changes.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.openjdk.jmh.annotations._
44
import scala.runtime.DynamicTuple
55

66
@State(Scope.Thread)
7-
class ApplyBenchmarks {
7+
class Apply {
88
@Param(Array("1 0"))
99
var sizeAndIndex: String = _
1010
var tuple: NonEmptyTuple = _
@@ -17,7 +17,7 @@ class ApplyBenchmarks {
1717
tuple = "elem" *: ()
1818

1919
for (i <- 1 until size)
20-
tuple = "string" *: tuple
20+
tuple = "elem" *: tuple
2121
}
2222

2323
@Benchmark
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 ArrayOps {
8+
@Param(Array("0"))
9+
var size: Int = _
10+
var tuple: Tuple = _
11+
var array: Array[Object] = _
12+
var iarray: IArray[Object] = _
13+
14+
@Setup
15+
def setup(): Unit = {
16+
tuple = ()
17+
18+
for (i <- 1 to size)
19+
tuple = "elem" *: tuple
20+
21+
array = Array.fill(size)("elem")
22+
iarray = IArray.fill(size)("elem")
23+
}
24+
25+
@Benchmark
26+
def baseline(): Unit = {}
27+
28+
@Benchmark
29+
def toArray(): Array[Object] = {
30+
DynamicTuple.dynamicToArray(tuple)
31+
}
32+
33+
@Benchmark
34+
def toIArray(): IArray[Object] = {
35+
DynamicTuple.dynamicToIArray(tuple)
36+
}
37+
38+
@Benchmark
39+
def fromArray(): Tuple = {
40+
DynamicTuple.dynamicFromArray(array)
41+
}
42+
43+
@Benchmark
44+
def fromIArray(): Tuple = {
45+
DynamicTuple.dynamicFromIArray(iarray)
46+
}
47+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Concat {
2525
val size1 = sizes.split(' ')(0).toInt
2626
val size2 = sizes.split(' ')(1).toInt
2727
tuple1 = tupleOfSize(size1)
28-
tuple1 = tupleOfSize(size2)
28+
tuple2 = tupleOfSize(size2)
2929
array1 = Array.fill(size1)("elem")
3030
array2 = Array.fill(size2)("elem")
3131
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 Cons {
8+
@Param(Array("0"))
9+
var size: Int = _
10+
var tuple: Tuple = _
11+
var array: Array[Object] = _
12+
13+
@Setup
14+
def setup(): Unit = {
15+
tuple = ()
16+
17+
for (i <- 1 to size)
18+
tuple = "elem" *: tuple
19+
20+
array = Array.fill(size)("elem")
21+
}
22+
23+
@Benchmark
24+
def baseline(): Unit = {}
25+
26+
@Benchmark
27+
def normal(): Tuple = {
28+
"elem" *: tuple
29+
}
30+
31+
@Benchmark
32+
def inlined(): Tuple = {
33+
DynamicTuple.dynamicCons("elem", tuple)
34+
}
35+
36+
// This part is here to measure the performance of dong a cons on arrays directly
37+
@Benchmark
38+
def arrayCons(): Array[Object] = {
39+
DynamicTuple.cons$Array("elem", array)
40+
}
41+
}

0 commit comments

Comments
 (0)