Skip to content

Commit a1cd519

Browse files
author
Abduqodiri Qurbonzoda
committed
Generate benchmark suites in their packages
1 parent 4995109 commit a1cd519

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package test.nested
2+
3+
import kotlinx.benchmark.*
4+
import kotlin.math.*
5+
6+
/**
7+
* This benchmark is to test that benchmarks with the same name but located in different packages
8+
* are handled correctly by the benchmarking plugin.
9+
*/
10+
@State(Scope.Benchmark)
11+
@Measurement(iterations = 3, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS)
12+
@OutputTimeUnit(BenchmarkTimeUnit.MILLISECONDS)
13+
@BenchmarkMode(Mode.Throughput)
14+
class CommonBenchmark {
15+
private var data = 0.0
16+
17+
@Setup
18+
fun setUp() {
19+
data = 3.0
20+
}
21+
22+
@Benchmark
23+
fun mathBenchmark(): Double {
24+
return log(sqrt(data) * cos(data), 2.0)
25+
}
26+
}

plugin/main/src/kotlinx/benchmark/gradle/SuiteSourceGenerator.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ class SuiteSourceGenerator(val title: String, val module: ModuleDescriptor, val
103103
val originalName = original.fqNameSafe.shortName()
104104
val originalClass = ClassName(originalPackage.toString(), originalName.toString())
105105

106-
val benchmarkPackageName = originalPackage.child(Name.identifier("generated")).toString()
106+
val benchmarkPackageName = "$mainBenchmarkPackage.$originalPackage"
107107
val benchmarkName = originalName.toString() + "_Descriptor"
108-
val benchmarkClass = ClassName(mainBenchmarkPackage, benchmarkName)
108+
val benchmarkClass = ClassName(benchmarkPackageName, benchmarkName)
109109

110110
val functions = DescriptorUtils.getAllDescriptors(original.unsubstitutedMemberScope)
111111
.filterIsInstance<FunctionDescriptor>()
@@ -145,7 +145,7 @@ class SuiteSourceGenerator(val title: String, val module: ModuleDescriptor, val
145145
val teardownFunctions = functions
146146
.filter { it.annotations.any { it.fqName.toString() == teardownAnnotationFQN } }.reversed()
147147

148-
val file = FileSpec.builder(mainBenchmarkPackage, benchmarkName).apply {
148+
val file = FileSpec.builder(benchmarkPackageName, benchmarkName).apply {
149149
declareObject(benchmarkClass) {
150150
addAnnotation(suppressUnusedParameter)
151151

0 commit comments

Comments
 (0)