Skip to content

Commit

Permalink
tool: add support for measuring runtime of a program
Browse files Browse the repository at this point in the history
  • Loading branch information
azenla committed Sep 5, 2023
1 parent 2631b67 commit 725137c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tool/src/main/kotlin/gay/pizza/pork/tool/RunCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,29 @@ import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.path
import gay.pizza.pork.evaluator.CallableFunction
import gay.pizza.pork.evaluator.Scope
import kotlin.system.measureTimeMillis

class RunCommand : CliktCommand(help = "Run Program", name = "run") {
val loop by option("--loop", help = "Loop Program").flag()
val measure by option("--measure", help = "Measure Time").flag()
val path by argument("file").path(mustExist = true, canBeDir = false)

override fun run() {
if (loop) {
while (true) {
runProgramMaybeMeasure()
}
} else {
runProgramMaybeMeasure()
}
}

private fun runProgramMaybeMeasure() {
if (measure) {
val time = measureTimeMillis {
runProgramOnce()
}
println("time taken: $time ms")
} else {
runProgramOnce()
}
Expand Down

0 comments on commit 725137c

Please sign in to comment.