[K/N] Deprecate getTime and measureTime functions
As a part of efforts to stabilize Native stdlib. Merge-request: KT-MR-9533 Merged-by: Abduqodiri Qurbonzoda <abduqodiri.qurbonzoda@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
077f49f33b
commit
0c89224955
@@ -6,10 +6,11 @@
|
||||
package kotlin.native.internal.test
|
||||
|
||||
import kotlin.IllegalArgumentException
|
||||
import kotlin.system.getTimeMillis
|
||||
import kotlin.system.measureTimeMillis
|
||||
import kotlin.text.StringBuilder
|
||||
import kotlin.time.TimeSource
|
||||
import kotlin.time.measureTime
|
||||
|
||||
@OptIn(kotlin.time.ExperimentalTime::class)
|
||||
internal class TestRunner(val suites: List<TestSuite>, args: Array<String>) {
|
||||
private val filters = mutableListOf<(TestCase) -> Boolean>()
|
||||
private val listeners = mutableSetOf<TestListener>()
|
||||
@@ -239,13 +240,13 @@ internal class TestRunner(val suites: List<TestSuite>, args: Array<String>) {
|
||||
if (testCase.ignored) {
|
||||
sendToListeners { ignore(testCase) }
|
||||
} else {
|
||||
val startTime = getTimeMillis()
|
||||
val startTime = TimeSource.Monotonic.markNow()
|
||||
try {
|
||||
sendToListeners { start(testCase) }
|
||||
testCase.run()
|
||||
sendToListeners { pass(testCase, getTimeMillis() - startTime) }
|
||||
sendToListeners { pass(testCase, startTime.elapsedNow().inWholeMilliseconds) }
|
||||
} catch (e: Throwable) {
|
||||
sendToListeners { fail(testCase, e, getTimeMillis() - startTime) }
|
||||
sendToListeners { fail(testCase, e, startTime.elapsedNow().inWholeMilliseconds) }
|
||||
if (useExitCode) {
|
||||
exitCode = 1
|
||||
}
|
||||
@@ -258,7 +259,7 @@ internal class TestRunner(val suites: List<TestSuite>, args: Array<String>) {
|
||||
private fun runIteration(iteration: Int) {
|
||||
val suitesFiltered = filterSuites()
|
||||
sendToListeners { startIteration(this@TestRunner, iteration, suitesFiltered) }
|
||||
val iterationTime = measureTimeMillis {
|
||||
val iterationTime = measureTime {
|
||||
suitesFiltered.forEach {
|
||||
if (it.ignored) {
|
||||
sendToListeners { ignoreSuite(it) }
|
||||
@@ -268,11 +269,11 @@ internal class TestRunner(val suites: List<TestSuite>, args: Array<String>) {
|
||||
return@forEach
|
||||
}
|
||||
sendToListeners { startSuite(it) }
|
||||
val time = measureTimeMillis { it.run() }
|
||||
val time = measureTime { it.run() }.inWholeMilliseconds
|
||||
sendToListeners { finishSuite(it, time) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}.inWholeMilliseconds
|
||||
sendToListeners { finishIteration(this@TestRunner, iteration, iterationTime) }
|
||||
}
|
||||
|
||||
@@ -280,13 +281,13 @@ internal class TestRunner(val suites: List<TestSuite>, args: Array<String>) {
|
||||
if (!runTests)
|
||||
return 0
|
||||
sendToListeners { startTesting(this@TestRunner) }
|
||||
val totalTime = measureTimeMillis {
|
||||
val totalTime = measureTime {
|
||||
var i = 1
|
||||
while (i <= iterations || iterations < 0) {
|
||||
runIteration(i)
|
||||
i++
|
||||
}
|
||||
}
|
||||
}.inWholeMilliseconds
|
||||
sendToListeners { finishTesting(this@TestRunner, totalTime) }
|
||||
return exitCode
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import kotlin.system.getTimeNanos
|
||||
*/
|
||||
internal object NativeRandom : Random() {
|
||||
private const val MULTIPLIER = 0x5deece66dL
|
||||
@Suppress("DEPRECATION")
|
||||
private val _seed = AtomicLong(mult(getTimeNanos()))
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,40 +6,91 @@
|
||||
package kotlin.system
|
||||
|
||||
import kotlin.native.internal.GCUnsafeCall
|
||||
import kotlin.time.*
|
||||
|
||||
/**
|
||||
* Gets current system time in milliseconds since certain moment in the past,
|
||||
* only delta between two subsequent calls makes sense.
|
||||
*
|
||||
* This function is deprecated.
|
||||
* To measure the duration of execution of a block of code,
|
||||
* use [measureTime] or [measureTimedValue] instead.
|
||||
* To mark a point in time for querying the duration of time interval [elapsed][TimeMark.elapsedNow]
|
||||
* from that point, use [TimeSource.Monotonic.markNow] instead.
|
||||
* The resulting [Duration] then can be expressed as a [Long] number of milliseconds
|
||||
* using [Duration.inWholeMilliseconds].
|
||||
*/
|
||||
@Deprecated("Use measureTime() or TimeSource.Monotonic.markNow() instead.")
|
||||
@DeprecatedSinceKotlin(warningSince = "1.9")
|
||||
@GCUnsafeCall("Kotlin_system_getTimeMillis")
|
||||
public external fun getTimeMillis() : Long
|
||||
|
||||
/**
|
||||
* Gets current system time in nanoseconds since certain moment in the past,
|
||||
* only delta between two subsequent calls makes sense.
|
||||
*
|
||||
* This function is deprecated.
|
||||
* To measure the duration of execution of a block of code,
|
||||
* use [measureTime] or [measureTimedValue] instead.
|
||||
* To mark a point in time for querying the duration of time interval [elapsed][TimeMark.elapsedNow]
|
||||
* from that point, use [TimeSource.Monotonic.markNow] instead.
|
||||
* The resulting [Duration] then can be expressed as a [Long] number of nanoseconds
|
||||
* using [Duration.inWholeNanoseconds].
|
||||
*/
|
||||
@Deprecated("Use measureTime() or TimeSource.Monotonic.markNow() instead.")
|
||||
@DeprecatedSinceKotlin(warningSince = "1.9")
|
||||
@GCUnsafeCall("Kotlin_system_getTimeNanos")
|
||||
public external fun getTimeNanos() : Long
|
||||
|
||||
/**
|
||||
* Gets current system time in microseconds since certain moment in the past,
|
||||
* only delta between two subsequent calls makes sense.
|
||||
*
|
||||
* This function is deprecated.
|
||||
* To measure the duration of execution of a block of code,
|
||||
* use [measureTime] or [measureTimedValue] instead.
|
||||
* To mark a point in time for querying the duration of time interval [elapsed][TimeMark.elapsedNow]
|
||||
* from that point, use [TimeSource.Monotonic.markNow] instead.
|
||||
* The resulting [Duration] then can be expressed as a [Long] number of microseconds
|
||||
* using [Duration.inWholeMicroseconds].
|
||||
*/
|
||||
@Deprecated("Use measureTime() or TimeSource.Monotonic.markNow() instead.")
|
||||
@DeprecatedSinceKotlin(warningSince = "1.9")
|
||||
@GCUnsafeCall("Kotlin_system_getTimeMicros")
|
||||
public external fun getTimeMicros() : Long
|
||||
|
||||
/**
|
||||
* Executes the given [block] and returns elapsed time in milliseconds.
|
||||
*
|
||||
* This function is deprecated.
|
||||
* To measure the duration of execution of a block of code,
|
||||
* use [measureTime] or [measureTimedValue] instead.
|
||||
* The resulting [Duration] then can be expressed as a [Long] number of milliseconds
|
||||
* using [Duration.inWholeMilliseconds].
|
||||
*
|
||||
* @sample samples.system.Timing.measureBlockTimeMillis
|
||||
*/
|
||||
@Deprecated("Use measureTime() instead.", ReplaceWith("measureTime(block).inWholeMilliseconds"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.9")
|
||||
@Suppress("DEPRECATION")
|
||||
public inline fun measureTimeMillis(block: () -> Unit) : Long {
|
||||
val start = getTimeMillis()
|
||||
block()
|
||||
return getTimeMillis() - start
|
||||
}
|
||||
|
||||
/** Executes the given [block] and returns elapsed time in microseconds (Kotlin/Native only). */
|
||||
/**
|
||||
* Executes the given [block] and returns elapsed time in microseconds (Kotlin/Native only).
|
||||
*
|
||||
* This function is deprecated.
|
||||
* To measure the duration of execution of a block of code,
|
||||
* use [measureTime] or [measureTimedValue] instead.
|
||||
* The resulting [Duration] then can be expressed as a [Long] number of microseconds
|
||||
* using [Duration.inWholeMicroseconds].
|
||||
*/
|
||||
@Deprecated("Use measureTime() instead.", ReplaceWith("measureTime(block).inWholeMicroseconds", "kotlin.time.measureTime"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.9")
|
||||
@Suppress("DEPRECATION")
|
||||
public inline fun measureTimeMicros(block: () -> Unit) : Long {
|
||||
val start = getTimeMicros()
|
||||
block()
|
||||
@@ -49,8 +100,17 @@ public inline fun measureTimeMicros(block: () -> Unit) : Long {
|
||||
/**
|
||||
* Executes the given [block] and returns elapsed time in nanoseconds.
|
||||
*
|
||||
* This function is deprecated.
|
||||
* To measure the duration of execution of a block of code,
|
||||
* use [measureTime] or [measureTimedValue] instead.
|
||||
* The resulting [Duration] then can be expressed as a [Long] number of nanoseconds
|
||||
* using [Duration.inWholeNanoseconds].
|
||||
*
|
||||
* @sample samples.system.Timing.measureBlockNanoTime
|
||||
*/
|
||||
@Deprecated("Use measureTime() instead.", ReplaceWith("measureTime(block).inWholeNanoseconds", "kotlin.time.measureTime"))
|
||||
@DeprecatedSinceKotlin(warningSince = "1.9")
|
||||
@Suppress("DEPRECATION")
|
||||
public inline fun measureNanoTime(block: () -> Unit) : Long {
|
||||
val start = getTimeNanos()
|
||||
block()
|
||||
|
||||
@@ -11,7 +11,9 @@ import kotlin.time.TimeSource.Monotonic.ValueTimeMark
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalTime
|
||||
internal actual object MonotonicTimeSource : TimeSource.WithComparableMarks {
|
||||
@Suppress("DEPRECATION")
|
||||
private val zero: Long = getTimeNanos()
|
||||
@Suppress("DEPRECATION")
|
||||
private fun read(): Long = getTimeNanos() - zero
|
||||
override fun toString(): String = "TimeSource(System.nanoTime())"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user