Skip to content

Commit bac583e

Browse files
quick Terminal bar graph comparing sorting algorithms
1 parent ebac78f commit bac583e

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

jmh-result.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"Benchmark","Mode","Threads","Samples","Score","Score Error (99.9%)","Unit"
2+
"benchmark.SortingBenchmark.benchmarkBubbleSort","avgt",1,5,0.125965,0.017152,"ms/op"
3+
"benchmark.SortingBenchmark.benchmarkCountingSort","avgt",1,5,0.004571,0.000333,"ms/op"
4+
"benchmark.SortingBenchmark.benchmarkHeapSort","avgt",1,5,0.074379,0.008178,"ms/op"
5+
"benchmark.SortingBenchmark.benchmarkInsertionSort","avgt",1,5,0.029439,0.005017,"ms/op"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package benchmark
2+
3+
import scala.io.Source
4+
import scala.util.{Try, Using}
5+
6+
object PlotBenchmarks {
7+
def main(args: Array[String]): Unit = {
8+
Using.resource(Source.fromFile("jmh-result.csv")) { source =>
9+
val lines = source.getLines().toList.drop(1) // Skip header
10+
11+
val data = lines.flatMap { line =>
12+
val cols = line.split(",").map(_.trim.replaceAll("^\"|\"$", "")) // Remove quotes
13+
Try {
14+
val benchmark = cols(0).split('.').last.replace("benchmark", "")
15+
val score = cols(4).toDouble // Correct column index for Score
16+
(benchmark, score)
17+
}.toOption
18+
}
19+
20+
val maxScore = data.map(_._2).max
21+
val scale = 50 / maxScore
22+
23+
println("Benchmark Results (ms/op)\n" + "=" * 50)
24+
data.foreach { case (algo, score) =>
25+
val bar = "#" * (score * scale).toInt
26+
printf("%-15s | %-50s | %.3f%n", algo, bar, score)
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)