mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 05:10: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 com.github.ajalt.clikt.parameters.types.path
|
||||||
import gay.pizza.pork.evaluator.CallableFunction
|
import gay.pizza.pork.evaluator.CallableFunction
|
||||||
import gay.pizza.pork.evaluator.Scope
|
import gay.pizza.pork.evaluator.Scope
|
||||||
|
import kotlin.system.measureTimeMillis
|
||||||
|
|
||||||
class RunCommand : CliktCommand(help = "Run Program", name = "run") {
|
class RunCommand : CliktCommand(help = "Run Program", name = "run") {
|
||||||
val loop by option("--loop", help = "Loop Program").flag()
|
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)
|
val path by argument("file").path(mustExist = true, canBeDir = false)
|
||||||
|
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (loop) {
|
if (loop) {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
runProgramMaybeMeasure()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
runProgramMaybeMeasure()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun runProgramMaybeMeasure() {
|
||||||
|
if (measure) {
|
||||||
|
val time = measureTimeMillis {
|
||||||
runProgramOnce()
|
runProgramOnce()
|
||||||
}
|
}
|
||||||
|
println("time taken: $time ms")
|
||||||
} else {
|
} else {
|
||||||
runProgramOnce()
|
runProgramOnce()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user