[K/N] More work to do for weak-sweeper in weak ref benchmarks
Merge-request: KT-MR-11899 Merged-by: Alexey Glushko <aleksei.glushko@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
a42cb2f37f
commit
3efd98df1a
@@ -236,9 +236,9 @@ class RingLauncher : Launcher() {
|
||||
"GenericArrayView.inlined" to BenchmarkEntryWithInit.create(::GenericArrayViewBenchmark, { inlined() }),
|
||||
"GenericArrayView.specialized" to BenchmarkEntryWithInit.create(::GenericArrayViewBenchmark, { specialized() }),
|
||||
"GenericArrayView.manual" to BenchmarkEntryWithInit.create(::GenericArrayViewBenchmark, { manual() }),
|
||||
"WeakRefBenchmark.aliveReference" to BenchmarkEntryWithInit.create(::WeakRefBenchmark, { aliveReference() }),
|
||||
"WeakRefBenchmark.deadReference" to BenchmarkEntryWithInit.create(::WeakRefBenchmark, { deadReference() }),
|
||||
"WeakRefBenchmark.dyingReference" to BenchmarkEntryWithInit.create(::WeakRefBenchmark, { dyingReference() }),
|
||||
"WeakRefBenchmark.aliveReference" to BenchmarkEntryWithInitAndValidation.create(::WeakRefBenchmark, { aliveReference() }, { clean() }),
|
||||
"WeakRefBenchmark.deadReference" to BenchmarkEntryWithInitAndValidation.create(::WeakRefBenchmark, { deadReference() }, { clean() }),
|
||||
"WeakRefBenchmark.dyingReference" to BenchmarkEntryWithInitAndValidation.create(::WeakRefBenchmark, { dyingReference() }, { clean() }),
|
||||
)
|
||||
|
||||
init {
|
||||
|
||||
@@ -51,6 +51,8 @@ private fun ReferenceWrapper.stress() = (1..REPEAT_COUNT).sumOf {
|
||||
|
||||
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class)
|
||||
open class WeakRefBenchmark {
|
||||
private val weight = Array(BENCHMARK_SIZE) { ReferenceWrapper.create() }
|
||||
|
||||
private val aliveRef = ReferenceWrapper.create()
|
||||
private val deadRef = ReferenceWrapper.create().apply {
|
||||
dispose()
|
||||
@@ -76,4 +78,8 @@ open class WeakRefBenchmark {
|
||||
|
||||
Blackhole.consume(ref.stress())
|
||||
}
|
||||
|
||||
fun clean() {
|
||||
weight.forEach { it.dispose() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,23 +38,26 @@ swiftLauncher.addBase(name: "createMultigraphOfInt", benchmark: companion.create
|
||||
lambda: { ($0 as! SwiftInteropBenchmarks).simpleFunction() }))
|
||||
swiftLauncher.addBase(
|
||||
name: "WeakRefBenchmark.aliveReference",
|
||||
benchmark: BenchmarkEntryWithInit.companion.create(
|
||||
benchmark: BenchmarkEntryWithInitAndValidation.companion.create(
|
||||
ctor: { return WeakRefBenchmark() },
|
||||
lambda: { ($0 as! WeakRefBenchmark).aliveReference() }
|
||||
benchmark: { ($0 as! WeakRefBenchmark).aliveReference() },
|
||||
validation: { ($0 as! WeakRefBenchmark).clean() }
|
||||
)
|
||||
)
|
||||
swiftLauncher.addBase(
|
||||
name: "WeakRefBenchmark.deadReference",
|
||||
benchmark: BenchmarkEntryWithInit.companion.create(
|
||||
benchmark: BenchmarkEntryWithInitAndValidation.companion.create(
|
||||
ctor: { return WeakRefBenchmark() },
|
||||
lambda: { ($0 as! WeakRefBenchmark).deadReference() }
|
||||
benchmark: { ($0 as! WeakRefBenchmark).deadReference() },
|
||||
validation: { ($0 as! WeakRefBenchmark).clean() }
|
||||
)
|
||||
)
|
||||
swiftLauncher.addBase(
|
||||
name: "WeakRefBenchmark.dyingReference",
|
||||
benchmark: BenchmarkEntryWithInit.companion.create(
|
||||
benchmark: BenchmarkEntryWithInitAndValidation.companion.create(
|
||||
ctor: { return WeakRefBenchmark() },
|
||||
lambda: { ($0 as! WeakRefBenchmark).dyingReference() }
|
||||
benchmark: { ($0 as! WeakRefBenchmark).dyingReference() },
|
||||
validation: { ($0 as! WeakRefBenchmark).clean() }
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import Foundation
|
||||
import benchmark
|
||||
|
||||
private let REPEAT_COUNT = 10000
|
||||
private let REFERENCES_COUNT = 3
|
||||
|
||||
private class ReferenceWrapper {
|
||||
private weak var weakRef: KotlinData?
|
||||
@@ -49,6 +48,8 @@ private func deadReferenceWrapper() -> ReferenceWrapper {
|
||||
}
|
||||
|
||||
class WeakRefBenchmark {
|
||||
private let weight = (0..<10_000).map { _ in ReferenceWrapper() }
|
||||
|
||||
private let aliveRef = ReferenceWrapper()
|
||||
private let deadRef = deadReferenceWrapper()
|
||||
|
||||
@@ -78,4 +79,8 @@ class WeakRefBenchmark {
|
||||
let counter = ref.stress()
|
||||
Blackhole.companion.consume(value: counter)
|
||||
}
|
||||
|
||||
func clean() {
|
||||
weight.forEach { $0.dispose() }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user