mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-02 12:50:55 +00:00
tool: add support for measuring runtime of a program
This commit is contained in:
parent
2631b6752b
commit
725137c82f
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user