Enhance progress logging in FIR total resolve tests

This commit is contained in:
Mikhail Glukhikh
2019-03-18 14:47:24 +03:00
parent a334ca6224
commit 741bdccca5
3 changed files with 17 additions and 17 deletions
@@ -32,8 +32,9 @@ fun doFirResolveTestBench(firFiles: List<FirFile>, transformers: List<FirTransfo
try {
for (transformer in transformers) {
for (firFile in firFiles) {
for ((stage, transformer) in transformers.withIndex()) {
println("Starting stage #$stage. $transformer")
for (firFile in firFiles.progress(" ~ ")) {
val time = measureNanoTime {
try {
transformer.transformFile(firFile, null)
@@ -116,4 +117,15 @@ fun doFirResolveTestBench(firFiles: List<FirFile>, transformers: List<FirTransfo
println("${transformer.simpleName}, TIME: ${time * 1e-6} ms, TIME PER FILE: ${(time / counter) * 1e-6} ms, FILES: $counter")
}
}
}
}
fun <T> Collection<T>.progress(label: String, step: Double = 0.1): Sequence<T> {
val intStep = (this.size * step).toInt()
var progress = 0
return asSequence().onEach {
if (progress % intStep == 0) {
println("$label: ${progress * 100 / size}% ($progress/${this.size})")
}
progress++
}
}