Make TimeMark returned by TimeSource.Monotonic a value class

This value class wraps Long on JVM and Native thus reducing allocations
in time measurement scenarios when the default monotonic time source is
statically known.

KT-46132
This commit is contained in:
Ilya Gorbunov
2022-01-25 00:47:21 +03:00
committed by Space
parent 5b45ea9bc9
commit fede70d0d5
11 changed files with 281 additions and 49 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -13,10 +13,12 @@ import kotlin.time.Duration.Companion.nanoseconds
class MeasureTimeTest {
private fun longRunningCalc(): String = buildString {
repeat(10) {
while (Random.nextDouble() >= 0.001);
append(('a'..'z').random())
companion object {
fun longRunningCalc(): String = buildString {
repeat(10) {
while (Random.nextDouble() >= 0.001);
append(('a'..'z').random())
}
}
}