Skip to content

Commit

Permalink
benchmark test duration
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Apr 29, 2024
1 parent a70ab97 commit e453210
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent.*
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.targets.js.nodejs.*
import kotlin.time.*
import kotlin.time.DurationUnit.MILLISECONDS

plugins {
signing
Expand Down Expand Up @@ -253,6 +255,12 @@ kotlin {
}
}

data class TestDuration(val name: String, val duration: Duration) {
override fun toString() = "$name: $duration"
}

val testDurations = mutableListOf<TestDuration>()

tasks {
withType<KotlinCompile> {
compilerOptions.jvmTarget = JvmTarget.JVM_17
Expand All @@ -276,6 +284,21 @@ tasks {
showStandardStreams = true
}

afterTest(
KotlinClosure2({ desc: TestDescriptor, result: TestResult ->
println("Completed `${desc.displayName}` in ${result.endTime - result.startTime}ms")
testDurations.add(TestDuration(
name = "${desc.className}.${desc.name}",
duration = (result.endTime - result.startTime).toDuration(MILLISECONDS)
))
})
)

doLast {
println("Longest 10 tests")
testDurations.sortedBy { it.duration }.reversed().take(10).forEach { println(it) }
}

if (project.hasProperty("leaseExcludeBenchmarks")) exclude("**/**Benchmarks.class")
}

Expand Down

0 comments on commit e453210

Please sign in to comment.