Skip to content

Commit 4c7af65

Browse files
Abduqodiri Qurbonzodaqurbonzoda
authored andcommitted
Make Blackhole.consume() functions inline
1 parent a3a3849 commit 4c7af65

File tree

2 files changed

+18
-37
lines changed

2 files changed

+18
-37
lines changed

runtime/api/kotlinx-benchmark-runtime.klib.api

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Klib ABI Dump
22
// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, js.jsIr, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, wasmJs, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
3-
// Alias: native => [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
43
// Rendering settings:
54
// - Signature version: 2
65
// - Show manifest properties: true
@@ -9,42 +8,19 @@
98
// Library unique name: <org.jetbrains.kotlinx:kotlinx-benchmark-runtime>
109
final class kotlinx.benchmark/Blackhole { // kotlinx.benchmark/Blackhole|null[0]
1110
constructor <init>() // kotlinx.benchmark/Blackhole.<init>|<init>(){}[0]
12-
// Targets: [native]
1311
final inline fun consume(kotlin/Any?) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Any?){}[0]
14-
// Targets: [native]
1512
final inline fun consume(kotlin/Boolean) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Boolean){}[0]
16-
// Targets: [native]
1713
final inline fun consume(kotlin/Byte) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Byte){}[0]
18-
// Targets: [native]
1914
final inline fun consume(kotlin/Char) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Char){}[0]
20-
// Targets: [native]
2115
final inline fun consume(kotlin/Double) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Double){}[0]
22-
// Targets: [native]
2316
final inline fun consume(kotlin/Float) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Float){}[0]
24-
// Targets: [native]
2517
final inline fun consume(kotlin/Int) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Int){}[0]
26-
// Targets: [native]
2718
final inline fun consume(kotlin/Long) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Long){}[0]
28-
// Targets: [native]
2919
final inline fun consume(kotlin/Short) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Short){}[0]
3020
// Targets: [js.jsIr, wasmJs]
31-
final fun consume(kotlin/Any?) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Any?){}[0]
21+
final fun consumeAny(kotlin/Any?) // kotlinx.benchmark/Blackhole.consumeAny|consumeAny(kotlin.Any?){}[0]
3222
// Targets: [js.jsIr, wasmJs]
33-
final fun consume(kotlin/Boolean) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Boolean){}[0]
34-
// Targets: [js.jsIr, wasmJs]
35-
final fun consume(kotlin/Byte) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Byte){}[0]
36-
// Targets: [js.jsIr, wasmJs]
37-
final fun consume(kotlin/Char) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Char){}[0]
38-
// Targets: [js.jsIr, wasmJs]
39-
final fun consume(kotlin/Double) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Double){}[0]
40-
// Targets: [js.jsIr, wasmJs]
41-
final fun consume(kotlin/Float) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Float){}[0]
42-
// Targets: [js.jsIr, wasmJs]
43-
final fun consume(kotlin/Int) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Int){}[0]
44-
// Targets: [js.jsIr, wasmJs]
45-
final fun consume(kotlin/Long) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Long){}[0]
46-
// Targets: [js.jsIr, wasmJs]
47-
final fun consume(kotlin/Short) // kotlinx.benchmark/Blackhole.consume|consume(kotlin.Short){}[0]
23+
final fun consumeInt(kotlin/Int) // kotlinx.benchmark/Blackhole.consumeInt|consumeInt(kotlin.Int){}[0]
4824
}
4925
final enum class kotlinx.benchmark/BenchmarkTimeUnit : kotlin/Enum<kotlinx.benchmark/BenchmarkTimeUnit> { // kotlinx.benchmark/BenchmarkTimeUnit|null[0]
5026
enum entry MICROSECONDS // kotlinx.benchmark/BenchmarkTimeUnit.MICROSECONDS|null[0]

runtime/jsWasmJsSharedMain/src/kotlinx/benchmark/CommonBlackhole.kt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ import kotlinx.benchmark.internal.KotlinxBenchmarkRuntimeInternalApi
44

55
private const val MAGIC_SIZE: Int = 13
66

7+
@Suppress("NOTHING_TO_INLINE")
78
public actual class Blackhole {
89
private val arrayOfAny: Array<Any?> = arrayOfNulls(MAGIC_SIZE)
910
private var currentAnyPosition: Int = 0
10-
private fun consumeAny(obj: Any?) {
11+
12+
@PublishedApi
13+
internal fun consumeAny(obj: Any?) {
1114
arrayOfAny[currentAnyPosition] = obj
1215
currentAnyPosition = if (currentAnyPosition == MAGIC_SIZE - 1) 0 else currentAnyPosition + 1
1316
}
1417

1518
private val arrayOfInt: IntArray = IntArray(MAGIC_SIZE)
1619
private var currentIntPosition: Int = 0
17-
private fun consumeInt(i: Int) {
20+
21+
@PublishedApi
22+
internal fun consumeInt(i: Int) {
1823
arrayOfInt[currentIntPosition] = i
1924
currentIntPosition = if (currentIntPosition == MAGIC_SIZE - 1) 0 else currentIntPosition + 1
2025
}
@@ -24,23 +29,23 @@ public actual class Blackhole {
2429
println("Consumed blackhole value: $sums")
2530
}
2631

27-
actual fun consume(obj: Any?) = consumeAny(obj)
32+
actual inline fun consume(obj: Any?) = consumeAny(obj)
2833

29-
actual fun consume(bool: Boolean) = consumeInt(bool.hashCode())
34+
actual inline fun consume(bool: Boolean) = consumeInt(bool.hashCode())
3035

31-
actual fun consume(c: Char) = consumeInt(c.hashCode())
36+
actual inline fun consume(c: Char) = consumeInt(c.hashCode())
3237

33-
actual fun consume(b: Byte) = consumeInt(b.hashCode())
38+
actual inline fun consume(b: Byte) = consumeInt(b.hashCode())
3439

35-
actual fun consume(s: Short) = consumeInt(s.hashCode())
40+
actual inline fun consume(s: Short) = consumeInt(s.hashCode())
3641

37-
actual fun consume(i: Int) = consumeInt(i.hashCode())
42+
actual inline fun consume(i: Int) = consumeInt(i.hashCode())
3843

39-
actual fun consume(l: Long) = consumeInt(l.hashCode())
44+
actual inline fun consume(l: Long) = consumeInt(l.hashCode())
4045

41-
actual fun consume(f: Float) = consumeInt(f.hashCode())
46+
actual inline fun consume(f: Float) = consumeInt(f.hashCode())
4247

43-
actual fun consume(d: Double) = consumeInt(d.hashCode())
48+
actual inline fun consume(d: Double) = consumeInt(d.hashCode())
4449
}
4550

4651

0 commit comments

Comments
 (0)