IJPL-162853 use kotlin function for measuring time

GitOrigin-RevId: 99b8ed9cf7d57704bb60a873db409646bafda817
This commit is contained in:
Max Medvedev
2025-04-12 14:47:00 +00:00
committed by intellij-monorepo-bot
parent 134be56b0a
commit e3cfcff5a7
2 changed files with 10 additions and 8 deletions
@@ -17,6 +17,7 @@ import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.NonNls
import kotlin.math.abs
import kotlin.math.max
import kotlin.time.measureTimedValue
internal class ParsingTreeBuilder(
val lexer: Lexer,
@@ -534,11 +535,10 @@ private fun performLexing(
return LexingResult(cachedLexemes, 0)
}
// todo do we need to cover a raw TokenList?
val startTime = System.nanoTime()
val sequence = performLexing(text, lexer, cancellationProvider, logger) as TokenSequence
val endTime = System.nanoTime()
return LexingResult(sequence, endTime - startTime)
val (sequence, duration) = measureTimedValue {
performLexing(text, lexer, cancellationProvider, logger) as TokenSequence
}
return LexingResult(sequence, duration.inWholeNanoseconds)
}
private data class LexingResult(val tokens: TokenSequence, val lexingTimeNs: Long)
@@ -7,6 +7,7 @@ import com.intellij.platform.syntax.Logger
import org.jetbrains.annotations.NonNls
import kotlin.math.max
import kotlin.math.min
import kotlin.time.measureTimedValue
internal class TokenSequence(
internal val lexStarts: IntArray,
@@ -67,9 +68,10 @@ internal class TokenListLexerImpl(
return
}
val start = System.currentTimeMillis()
start(buffer, startOffset, endOffset, initialState)
val startDuration = System.currentTimeMillis() - start
val (_, duration) = measureTimedValue {
start(buffer, startOffset, endOffset, initialState)
}
val startDuration = duration.inWholeNanoseconds
if (startDuration > LEXER_START_THRESHOLD) {
logger.debug("Starting lexer took: $startDuration; at $startOffset - $endOffset; state: $initialState; text: ${buffer.shortenTextWithEllipsis(1024, 500)}")
}