File tree Expand file tree Collapse file tree 5 files changed +47
-47
lines changed
bench-run/src/main/scala/tuples Expand file tree Collapse file tree 5 files changed +47
-47
lines changed Original file line number Diff line number Diff line change @@ -21,15 +21,12 @@ class Apply {
21
21
}
22
22
23
23
@ Benchmark
24
- def baseline (): Unit = {}
25
-
26
- @ Benchmark
27
- def normal (): Any = {
28
- tuple(index)
24
+ def tupleApply (): Any = {
25
+ DynamicTuple .dynamicApply(tuple, index)
29
26
}
30
27
31
28
@ Benchmark
32
- def inlined (): Any = {
33
- DynamicTuple .dynamicApply(tuple, index)
29
+ def productElement (): Any = {
30
+ tuple. asInstanceOf [ Product ].productElement( index)
34
31
}
35
32
}
Original file line number Diff line number Diff line change @@ -23,25 +23,27 @@ class ArrayOps {
23
23
}
24
24
25
25
@ Benchmark
26
- def baseline (): Unit = {}
27
-
28
- @ Benchmark
29
- def toArray (): Array [Object ] = {
26
+ def tupleToArray (): Array [Object ] = {
30
27
DynamicTuple .dynamicToArray(tuple)
31
28
}
32
29
33
30
@ Benchmark
34
- def toIArray (): IArray [Object ] = {
31
+ def tupleToIArray (): IArray [Object ] = {
35
32
DynamicTuple .dynamicToIArray(tuple)
36
33
}
37
34
38
35
@ Benchmark
39
- def fromArray (): Tuple = {
36
+ def tupleFromArray (): Tuple = {
40
37
DynamicTuple .dynamicFromArray(array)
41
38
}
42
39
43
40
@ Benchmark
44
- def fromIArray (): Tuple = {
41
+ def tupleFromIArray (): Tuple = {
45
42
DynamicTuple .dynamicFromIArray(iarray)
46
43
}
44
+
45
+ @ Benchmark
46
+ def productToArray (): Array [Object ] = {
47
+ DynamicTuple .productToArray(tuple.asInstanceOf [Product ])
48
+ }
47
49
}
Original file line number Diff line number Diff line change @@ -31,34 +31,12 @@ class Concat {
31
31
}
32
32
33
33
@ 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 = {
43
35
DynamicTuple .dynamicConcat(tuple1, tuple2)
44
36
}
45
37
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
-
54
38
@ Benchmark
55
39
def arrayConcat (): Array [Object ] = {
56
40
array1 ++ array2
57
41
}
58
-
59
- @ Benchmark
60
- def fromArray (bh : Blackhole ): Unit = {
61
- bh.consume(DynamicTuple .dynamicFromArray[Tuple ](array1))
62
- bh.consume(DynamicTuple .dynamicFromArray[Tuple ](array2))
63
- }
64
42
}
Original file line number Diff line number Diff line change @@ -21,19 +21,10 @@ class Cons {
21
21
}
22
22
23
23
@ 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 = {
33
25
DynamicTuple .dynamicCons(" elem" , tuple)
34
26
}
35
27
36
- // This part is here to measure the performance of dong a cons on arrays directly
37
28
@ Benchmark
38
29
def arrayCons (): Array [Object ] = {
39
30
DynamicTuple .cons$Array (" elem" , array)
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments