Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add util to print benchmark runs to tsv file #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions bench/TsvPrinter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ichi.bench

import ichi.bench.Thyme.Benched
import java.io.{PrintWriter, File}

/**
* Util for writing the results of a benchmark to a tsv file, so they can
* be easily read in by an external program, eg. for graphing
*/
class TsvPrinter(val th: Thyme, val file: File) {
val out = new PrintWriter(file)
out.println("title\truntime")

def addToTsv(benched: Benched) {
benched.runtimeResults.data.value.foreach{runtime =>
out.println(benched.title + "\t" + (runtime / benched.runtimeEffort))
}
}

def close() {out.close()}

/**
* Run the benchmark and print the answer, like pbench, but also write
* the times from each run to the tsv file
*/
def tsvBench[A](f: => A, effort: Int = 1, title: String = "") = {
val br = Thyme.Benched.empty
br.title = title
val ans = th.bench(f)(br, effort = effort)
println(br)
addToTsv(br)
ans
}

/**
* Print out a command you can paste into R to generate a boxplot
*/
def showRCommand = println(
"""data <- read.table("""" + file.getAbsolutePath +
"""", sep="\t",h=T)
|# you might want to reorder the plot with something like:
|# data$title = factor(data$title, levels = c(<desired order>), ordered=T)
|boxplot(runtime ~ title, data, ylab="seconds")
""".stripMargin
)
}

11 changes: 10 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ MATHS = \
BENCHES = \
ichi/bench/JvmStatus.class \
ichi/bench/Thyme.class \
ichi/bench/Parsley.class
ichi/bench/Parsley.class \
ichi/bench/TsvPrinter.class

EXAMPLES = \
ichi/bench/examples/ParsleyExample.class \
Expand Down Expand Up @@ -64,6 +65,14 @@ ichi/bench/Parsley.class : \
bench/Parsley.scala
scalac bench/Parsley.scala

ichi/bench/TsvPrinter.class : \
makefile \
${MATHS} \
ichi/bench/JvmStatus.class \
ichi/bench/Thyme.class \
bench/TsvPrinter.scala
scalac bench/TsvPrinter.scala

ichi/bench/examples/ParsleyExample.class : \
makefile \
${MATHS} \
Expand Down