Skip to content

Commit 013b93c

Browse files
author
Antoine Brunner
committed
Add output file support and benchmark filtering
1 parent 9197528 commit 013b93c

File tree

2 files changed

+85
-72
lines changed

2 files changed

+85
-72
lines changed

bench-run/src/main/scala/Benchmarks.scala

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ object Bench {
2222
val iterations = if (intArgs.length > 1) intArgs(1).toInt else 20
2323
val forks = if (intArgs.length > 2) intArgs(2).toInt else 1
2424

25+
val benchmarks = if (args1.length > 0) args1(0) else ".*"
26+
val outputFile = if (args1.length > 1) args1(1) else "output.csv"
27+
2528
val opts = new OptionsBuilder()
2629
.shouldFailOnError(true)
2730
.jvmArgs("-Xms2G", "-Xmx2G")
@@ -30,81 +33,12 @@ object Bench {
3033
.warmupIterations(warmup)
3134
.measurementIterations(iterations)
3235
.forks(forks)
36+
.include(benchmarks)
37+
.resultFormat(ResultFormatType.CSV)
38+
.result("results/" ++ outputFile)
3339
.build
3440

3541
val runner = new Runner(opts) // full access to all JMH features, you can also provide a custom output Format here
3642
runner.run() // actually run the benchmarks
3743
}
3844
}
39-
40-
@State(Scope.Thread)
41-
class ConsConcatBenchmarks {
42-
@Param(Array("10", "20"))
43-
var size: Int = _
44-
var tuple: Tuple = _
45-
46-
@Setup
47-
def setup(): Unit = {
48-
tuple = ()
49-
50-
for (i <- 1 to size)
51-
tuple = "string" *: tuple
52-
}
53-
54-
@Benchmark
55-
def baseline(): Unit = {}
56-
57-
// Cons benchmarks
58-
@Benchmark
59-
def tupleCons(): Tuple = {
60-
"string" *: tuple
61-
}
62-
63-
@Benchmark
64-
def dynamicTupleCons(): Tuple = {
65-
DynamicTuple.dynamicCons("string", tuple)
66-
}
67-
68-
// Concat benchmarks
69-
@Benchmark
70-
def tupleConcat(): Tuple = {
71-
tuple ++ tuple
72-
}
73-
74-
@Benchmark
75-
def dynamicTupleConcat(): Tuple = {
76-
DynamicTuple.dynamicConcat(tuple, tuple)
77-
}
78-
79-
// Interesting behaviour : I expect the two following to be the same because of TupleOptimizations.scala
80-
@Benchmark
81-
def tupleConcat2(): Tuple = {
82-
("string", "string") ++ ("string", "string")
83-
}
84-
85-
@Benchmark
86-
def tupleNoConcat(): Tuple = {
87-
("string", "string", "string", "string")
88-
}
89-
}
90-
91-
@State(Scope.Thread)
92-
class ApplyBenchmarks {
93-
val size: Int = 100
94-
95-
val tuple: NonEmptyTuple = {
96-
var t = ()
97-
for (i <- 1 to size)
98-
t = "string" *: t
99-
t.asInstanceOf[NonEmptyTuple]
100-
}
101-
102-
@Param(Array("1", "10", "25", "50", "75", "99"))
103-
var index: Int = _
104-
105-
// Apply benchmarks, doesn't work for some reason
106-
// @Benchmark
107-
// def tupleApply(): Unit = {
108-
// DynamicTuple.dynamicApply(tuple, index)
109-
// }
110-
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 ConsConcatBenchmarks {
8+
@Param(Array("10", "20"))
9+
var size: Int = _
10+
var tuple: Tuple = _
11+
12+
@Setup
13+
def setup(): Unit = {
14+
tuple = ()
15+
16+
for (i <- 1 to size)
17+
tuple = "string" *: tuple
18+
}
19+
20+
@Benchmark
21+
def baseline(): Unit = {}
22+
23+
// Cons benchmarks
24+
@Benchmark
25+
def tupleCons(): Tuple = {
26+
"string" *: tuple
27+
}
28+
29+
@Benchmark
30+
def dynamicTupleCons(): Tuple = {
31+
DynamicTuple.dynamicCons("string", tuple)
32+
}
33+
34+
// Concat benchmarks
35+
@Benchmark
36+
def tupleConcat(): Tuple = {
37+
tuple ++ tuple
38+
}
39+
40+
@Benchmark
41+
def dynamicTupleConcat(): Tuple = {
42+
DynamicTuple.dynamicConcat(tuple, tuple)
43+
}
44+
45+
// Interesting behaviour : I expect the two following to be the same because of TupleOptimizations.scala
46+
@Benchmark
47+
def tupleConcat2(): Tuple = {
48+
("string", "string") ++ ("string", "string")
49+
}
50+
51+
@Benchmark
52+
def tupleNoConcat(): Tuple = {
53+
("string", "string", "string", "string")
54+
}
55+
}
56+
57+
@State(Scope.Thread)
58+
class ApplyBenchmarks {
59+
val size: Int = 100
60+
61+
val tuple: NonEmptyTuple = {
62+
var t: Tuple = ()
63+
for (i <- 1 to size)
64+
t = "string" *: t
65+
t.asInstanceOf[NonEmptyTuple]
66+
}
67+
68+
@Param(Array("1", "10", "25", "50", "75", "99"))
69+
var index: Int = _
70+
71+
@Benchmark
72+
def baseline(): Unit = {}
73+
74+
// Apply benchmarks, doesn't work for some reason
75+
// @Benchmark
76+
// def tupleApply(): Unit = {
77+
// DynamicTuple.dynamicApply(tuple, index)
78+
// }
79+
}

0 commit comments

Comments
 (0)