mirror of
				https://github.com/GayPizzaSpecifications/pork.git
				synced 2025-11-04 09:59:39 +00:00 
			
		
		
		
	tool: add support for measuring runtime of a program
This commit is contained in:
		@ -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()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user