@@ -12,26 +12,35 @@ import org.jetbrains.kotlin.resolve.scopes.*
12
12
import org.jetbrains.kotlin.types.*
13
13
import java.io.*
14
14
15
- enum class Platform (val executorClass : String , val suiteDescriptorClass : String , val benchmarkDescriptorClass : String ) {
15
+ enum class Platform (
16
+ val executorClass : String ,
17
+ val suiteDescriptorClass : String ,
18
+ val benchmarkDescriptorClass : String ,
19
+ val benchmarkDescriptorWithBlackholeParameterClass : String
20
+ ) {
16
21
JsBuiltIn (
17
22
executorClass = " kotlinx.benchmark.js.JsSimpleExecutor" ,
18
23
suiteDescriptorClass = " kotlinx.benchmark.SuiteDescriptor" ,
19
- benchmarkDescriptorClass = " kotlinx.benchmark.js.JsBenchmarkDescriptor" ,
24
+ benchmarkDescriptorClass = " kotlinx.benchmark.js.JsBenchmarkDescriptorWithNoBlackholeParameter" ,
25
+ benchmarkDescriptorWithBlackholeParameterClass = " kotlinx.benchmark.js.JsBenchmarkDescriptorWithBlackholeParameter" ,
20
26
),
21
27
JsBenchmarkJs (
22
28
executorClass = " kotlinx.benchmark.js.JsExecutor" ,
23
29
suiteDescriptorClass = " kotlinx.benchmark.SuiteDescriptor" ,
24
- benchmarkDescriptorClass = " kotlinx.benchmark.js.JsBenchmarkDescriptor" ,
30
+ benchmarkDescriptorClass = " kotlinx.benchmark.js.JsBenchmarkDescriptorWithNoBlackholeParameter" ,
31
+ benchmarkDescriptorWithBlackholeParameterClass = " kotlinx.benchmark.js.JsBenchmarkDescriptorWithBlackholeParameter" ,
25
32
),
26
33
NativeBuiltIn (
27
34
executorClass = " kotlinx.benchmark.native.NativeExecutor" ,
28
35
suiteDescriptorClass = " kotlinx.benchmark.SuiteDescriptor" ,
29
- benchmarkDescriptorClass = " kotlinx.benchmark.native.NativeBenchmarkDescriptor" ,
36
+ benchmarkDescriptorClass = " kotlinx.benchmark.BenchmarkDescriptorWithNoBlackholeParameter" ,
37
+ benchmarkDescriptorWithBlackholeParameterClass = " kotlinx.benchmark.BenchmarkDescriptorWithBlackholeParameter" ,
30
38
),
31
39
WasmBuiltIn (
32
40
executorClass = " kotlinx.benchmark.wasm.WasmExecutor" ,
33
41
suiteDescriptorClass = " kotlinx.benchmark.SuiteDescriptor" ,
34
- benchmarkDescriptorClass = " kotlinx.benchmark.wasm.WasmBenchmarkDescriptor" ,
42
+ benchmarkDescriptorClass = " kotlinx.benchmark.BenchmarkDescriptorWithNoBlackholeParameter" ,
43
+ benchmarkDescriptorWithBlackholeParameterClass = " kotlinx.benchmark.BenchmarkDescriptorWithBlackholeParameter" ,
35
44
)
36
45
}
37
46
@@ -40,7 +49,6 @@ class SuiteSourceGenerator(val title: String, val module: ModuleDescriptor, val
40
49
val setupFunctionName = " setUp"
41
50
val teardownFunctionName = " tearDown"
42
51
val parametersFunctionName = " parametrize"
43
- val bindBlackholeFunctionName = " bind"
44
52
45
53
val externalConfigurationFQN = " kotlinx.benchmark.ExternalConfiguration"
46
54
val benchmarkAnnotationFQN = " kotlinx.benchmark.Benchmark"
@@ -65,7 +73,6 @@ class SuiteSourceGenerator(val title: String, val module: ModuleDescriptor, val
65
73
66
74
private val executorType = ClassName .bestGuess(platform.executorClass)
67
75
private val suiteDescriptorType = ClassName .bestGuess(platform.suiteDescriptorClass)
68
- private val benchmarkDescriptorType = ClassName .bestGuess(platform.benchmarkDescriptorClass)
69
76
70
77
val benchmarks = mutableListOf<ClassName >()
71
78
@@ -130,6 +137,7 @@ class SuiteSourceGenerator(val title: String, val module: ModuleDescriptor, val
130
137
val outputTimeUnitValue = outputTimeAnnotation?.argumentValue(" value" ) as ? EnumValue
131
138
val outputTimeUnit = outputTimeUnitValue?.enumEntryName?.toString()
132
139
140
+ @Suppress(" UNCHECKED_CAST" )
133
141
val modesValue = modeAnnotation?.argumentValue(" value" )?.value as ? List <EnumValue >
134
142
val mode = modesValue?.single()?.enumEntryName?.toString()
135
143
@@ -190,32 +198,11 @@ class SuiteSourceGenerator(val title: String, val module: ModuleDescriptor, val
190
198
}
191
199
}
192
200
193
- val bhClass = ClassName .bestGuess(blackholeFQN)
194
-
195
- /*
196
- private fun bind(function: CommonBenchmark.(Blackhole) -> Any?, bh: Blackhole): CommonBenchmark.() -> Any? {
197
- return { function(bh) }
198
- }
199
- */
200
- function(bindBlackholeFunctionName) {
201
- addModifiers(KModifier .PRIVATE )
202
-
203
- val bhParam = ParameterSpec .unnamed(bhClass)
204
- val bhBenchType = LambdaTypeName .get(originalClass, listOf (bhParam), ANY .copy(nullable = true ))
205
- val boundBenchType = LambdaTypeName .get(originalClass, emptyList(), ANY .copy(nullable = true ))
206
-
207
- addParameter(" function" , bhBenchType)
208
- addParameter(" bh" , bhClass)
209
- returns(boundBenchType)
210
-
211
- addStatement(" return { function(bh) }" )
212
- }
213
-
214
-
215
201
val defaultParameters = parameterProperties.associateBy({ it.name }, {
216
202
val annotation = it.annotations.findAnnotation(FqName (paramAnnotationFQN))!!
217
203
val constant = annotation.argumentValue(" value" )
218
204
? : error(" @Param annotation should have at least one default value" )
205
+ @Suppress(" UNCHECKED_CAST" )
219
206
val values = constant.value as ? List <StringValue >
220
207
? : error(" @Param annotation should have at least one default value" )
221
208
values
@@ -271,31 +258,25 @@ class SuiteSourceGenerator(val title: String, val module: ModuleDescriptor, val
271
258
)
272
259
addCode(" )\n »" )
273
260
addStatement(" " )
261
+
262
+ val bhClass = ClassName .bestGuess(blackholeFQN)
274
263
for (fn in benchmarkFunctions) {
275
264
val functionName = fn.name.toString()
276
265
277
266
val hasABlackholeParameter = fn.valueParameters.singleOrNull()?.type.toString() == " Blackhole"
278
- if (hasABlackholeParameter) {
279
- println (" WARNING: Blackhole works incorrectly on JS" )
280
-
281
- addStatement(
282
- " descriptor.add(%T(%S, descriptor, %N(%T::%N, %T())))" ,
283
- benchmarkDescriptorType,
284
- " ${originalClass.canonicalName} .$functionName " ,
285
- bindBlackholeFunctionName,
286
- originalClass,
287
- functionName,
288
- bhClass
289
- )
290
- }
291
- else
292
- addStatement(
293
- " descriptor.add(%T(%S, descriptor, %T::%N))" ,
294
- benchmarkDescriptorType,
295
- " ${originalClass.canonicalName} .$functionName " ,
296
- originalClass,
297
- functionName
298
- )
267
+
268
+ val fqnDescriptorToCreate =
269
+ if (hasABlackholeParameter) platform.benchmarkDescriptorWithBlackholeParameterClass
270
+ else platform.benchmarkDescriptorClass
271
+
272
+ addStatement(
273
+ " descriptor.add(%T(%S, descriptor, %T(), %T::%N))" ,
274
+ ClassName .bestGuess(fqnDescriptorToCreate),
275
+ " ${originalClass.canonicalName} .$functionName " ,
276
+ bhClass,
277
+ originalClass,
278
+ functionName
279
+ )
299
280
}
300
281
addStatement(" return descriptor" )
301
282
}
0 commit comments