mirror of https://github.com/sbt/sbt.git
Remove return statements in UpdateReportPersistenceBenchmark
This commit is contained in:
parent
87d8ae3a6c
commit
324f863d60
|
|
@ -31,60 +31,61 @@ final case class BenchmarkResult(
|
||||||
|
|
||||||
object UpdateReportPersistenceBenchmark:
|
object UpdateReportPersistenceBenchmark:
|
||||||
|
|
||||||
@SuppressWarnings(Array("scalafix:DisableSyntax"))
|
|
||||||
def run(
|
def run(
|
||||||
iterations: Int = 500,
|
iterations: Int = 500,
|
||||||
configs: Seq[String] = Seq("compile", "test"),
|
configs: Seq[String] = Seq("compile", "test"),
|
||||||
modulesPerConfig: Int = 50,
|
modulesPerConfig: Int = 50,
|
||||||
warmupIterations: Int = 10
|
warmupIterations: Int = 10
|
||||||
): Either[String, BenchmarkResult] =
|
): Either[String, BenchmarkResult] =
|
||||||
if iterations <= 0 then return Left("iterations must be positive")
|
for {
|
||||||
if configs.isEmpty then return Left("configs must be non-empty")
|
_ <- Either.cond(iterations > 0, (), "iterations must be positive")
|
||||||
if modulesPerConfig <= 0 then return Left("modulesPerConfig must be positive")
|
_ <- Either.cond(configs.nonEmpty, (), "configs must be non-empty")
|
||||||
if warmupIterations < 0 then return Left("warmupIterations must be non-negative")
|
_ <- Either.cond(modulesPerConfig > 0, (), "modulesPerConfig must be positive")
|
||||||
|
_ <- Either.cond(warmupIterations >= 0, (), "warmupIterations must be non-negative")
|
||||||
|
baseDir = IO.createTemporaryDirectory
|
||||||
|
result <-
|
||||||
|
try
|
||||||
|
val report = buildSampleReport(baseDir, configs, modulesPerConfig)
|
||||||
|
val fullStore = CacheStore(new File(baseDir, "full-format.json"))
|
||||||
|
val cacheStore = CacheStore(new File(baseDir, "cache-format.json"))
|
||||||
|
|
||||||
val baseDir = IO.createTemporaryDirectory
|
fullStore.write(report)
|
||||||
try
|
UpdateReportPersistence.writeTo(cacheStore, UpdateReportPersistence.toCache(report))
|
||||||
val report = buildSampleReport(baseDir, configs, modulesPerConfig)
|
|
||||||
val fullStore = CacheStore(new File(baseDir, "full-format.json"))
|
|
||||||
val cacheStore = CacheStore(new File(baseDir, "cache-format.json"))
|
|
||||||
|
|
||||||
fullStore.write(report)
|
for _ <- 0 until warmupIterations do
|
||||||
UpdateReportPersistence.writeTo(cacheStore, UpdateReportPersistence.toCache(report))
|
fullStore.read[UpdateReport]()
|
||||||
|
UpdateReportPersistence
|
||||||
|
.readFrom(cacheStore)
|
||||||
|
.map(UpdateReportPersistence.fromCache)
|
||||||
|
.getOrElse(sys.error("Expected cache report during warmup"))
|
||||||
|
|
||||||
for _ <- 0 until warmupIterations do
|
val fullStart = System.currentTimeMillis()
|
||||||
fullStore.read[UpdateReport]()
|
for _ <- 0 until iterations do fullStore.read[UpdateReport]()
|
||||||
UpdateReportPersistence
|
val fullEnd = System.currentTimeMillis()
|
||||||
.readFrom(cacheStore)
|
|
||||||
.map(UpdateReportPersistence.fromCache)
|
|
||||||
.getOrElse(sys.error("Expected cache report during warmup"))
|
|
||||||
|
|
||||||
val fullStart = System.currentTimeMillis()
|
val cacheStart = System.currentTimeMillis()
|
||||||
for _ <- 0 until iterations do fullStore.read[UpdateReport]()
|
for _ <- 0 until iterations do
|
||||||
val fullEnd = System.currentTimeMillis()
|
UpdateReportPersistence
|
||||||
|
.readFrom(cacheStore)
|
||||||
|
.map(UpdateReportPersistence.fromCache)
|
||||||
|
.getOrElse(sys.error("Expected cache report during benchmark"))
|
||||||
|
val cacheEnd = System.currentTimeMillis()
|
||||||
|
|
||||||
val cacheStart = System.currentTimeMillis()
|
val fullSize = new File(baseDir, "full-format.json").length()
|
||||||
for _ <- 0 until iterations do
|
val cacheSize = new File(baseDir, "cache-format.json").length()
|
||||||
UpdateReportPersistence
|
|
||||||
.readFrom(cacheStore)
|
|
||||||
.map(UpdateReportPersistence.fromCache)
|
|
||||||
.getOrElse(sys.error("Expected cache report during benchmark"))
|
|
||||||
val cacheEnd = System.currentTimeMillis()
|
|
||||||
|
|
||||||
val fullSize = new File(baseDir, "full-format.json").length()
|
Right(
|
||||||
val cacheSize = new File(baseDir, "cache-format.json").length()
|
BenchmarkResult(
|
||||||
|
iterationCount = iterations,
|
||||||
Right(
|
fullFormatMs = fullEnd - fullStart,
|
||||||
BenchmarkResult(
|
cacheFormatMs = cacheEnd - cacheStart,
|
||||||
iterationCount = iterations,
|
fullSizeBytes = fullSize,
|
||||||
fullFormatMs = fullEnd - fullStart,
|
cacheSizeBytes = cacheSize
|
||||||
cacheFormatMs = cacheEnd - cacheStart,
|
)
|
||||||
fullSizeBytes = fullSize,
|
)
|
||||||
cacheSizeBytes = cacheSize
|
catch case e: Exception => Left(s"Benchmark failed: ${e.getMessage}")
|
||||||
)
|
finally IO.delete(baseDir)
|
||||||
)
|
} yield result
|
||||||
catch case e: Exception => Left(s"Benchmark failed: ${e.getMessage}")
|
|
||||||
finally IO.delete(baseDir)
|
|
||||||
|
|
||||||
def buildSampleReport(
|
def buildSampleReport(
|
||||||
baseDir: File,
|
baseDir: File,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue