Last active
November 30, 2020 16:00
-
-
Save sorokod/f5431b209e096f54e56c8c8ece2eb504 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TimingLogger( | |
private val step: Long, | |
private val timeUnit: TimeUnit, | |
private val template: String, | |
private val counterScaler: Long = 1, | |
private val log: (String) -> Unit | |
) { | |
private var tickCounter: Long = 0L | |
private var timeMark = System.nanoTime() | |
fun tick() { | |
tickCounter++ | |
if ((tickCounter % step) == 0L) { | |
val t = timeUnit.convert(System.nanoTime() - timeMark, NANOSECONDS) | |
val n = tickCounter / counterScaler | |
timeMark = System.nanoTime() | |
log(template.format(n, t)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment