Skip to content

Instantly share code, notes, and snippets.

@AndrewReitz
Created March 14, 2019 16:41
Show Gist options
  • Save AndrewReitz/a4f91870a6c82df56728b32d4b6470c0 to your computer and use it in GitHub Desktop.
Save AndrewReitz/a4f91870a6c82df56728b32d4b6470c0 to your computer and use it in GitHub Desktop.
create two giant projects one with and one without serialVersionUID and benchmark compilation of them
#!/bin/bash
//usr/bin/env echo '
/**** BOOTSTRAP kscript ****\'>/dev/null
command -v kscript >/dev/null 2>&1 || curl -L "https://git.io/fpF1K" | bash 1>&2
exec kscript $0 "$@"
\*** IMPORTANT: Any code including imports and annotations must come after this line ***/
import java.io.File
import java.util.concurrent.TimeUnit
val buildScript = """
plugins {
kotlin("jvm") version "1.3.21"
}
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
}
""".trimIndent()
val noUuidProject = run {
val noUuidProject = File("NoSerialVersionUID").apply {
if (exists()) return@run this
mkdir()
}
File(noUuidProject, "build.gradle.kts").writeText(buildScript)
val noUuidSrc = File(noUuidProject, "src/main/kotlin").apply {
mkdirs()
}
(1..10_000).forEach {
val className = "Class$it"
val classContents = """
import java.io.Serializable
data class $className(val a: String) : Serializable
""".trimIndent()
File(noUuidSrc, "$className.kt").writeText(classContents)
}
return@run noUuidProject
}
val uuidProject = run {
val uuidProject = File("SerialVersionUID").apply {
if (exists()) return@run this
mkdirs()
}
File(uuidProject, "build.gradle.kts").writeText(buildScript)
val uuidSrc = File(uuidProject, "src/main/kotlin").apply {
mkdirs()
}
(1..10_000).forEach {
val className = "Class$it"
val classContents = """
import java.io.Serializable
data class $className(val a: String) : Serializable {
companion object {
private const val serialVersionUID = 42L
}
}
""".trimIndent()
File(uuidSrc, "$className.kt").writeText(classContents)
}
return@run uuidProject
}
ProcessBuilder("gradle-profiler", "--output-dir", "no-serialVersionUID-benchmark", "--benchmark", "--gradle-version", "5.2.1", "--project-dir", noUuidProject.absolutePath, "clean", "build")
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
.waitFor(60, TimeUnit.MINUTES)
ProcessBuilder("gradle-profiler", "--output-dir", "serialVersionUID-benchmark", "--benchmark", "--gradle-version", "5.2.1", "--project-dir", uuidProject.absolutePath, "clean", "build")
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
.waitFor(60, TimeUnit.MINUTES)
val noCsv = File("no-serialVersionUID-benchmark", "benchmark.csv")
val csv = File("serialVersionUID-benchmark", "benchmark.csv")
val noCsvMap = noCsv.readLines()
.drop(3)
.asSequence()
.map { it.split(",", limit = 2) }
.map { it[0].trim() to it[1].trim() }
.toMap()
val csvMap = csv.readLines()
.drop(3)
.asSequence()
.map { it.split(",", limit = 2) }
.map { it[0].trim() to it[1].trim() }
.toMap()
println("No serialVersionUID Mean: ${noCsvMap["mean"]} MilliSeconds")
println("No serialVersionUID Median: ${noCsvMap["median"]} MilliSeconds")
println("serialVersionUID Mean: ${csvMap["mean"]} MilliSeconds")
println("serialVersionUID Median: ${csvMap["median"]} MilliSeconds")
println("Difference of ${noCsvMap.getValue("mean").toBigDecimal() - csvMap.getValue("mean").toBigDecimal()} MilliSeconds")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment