mirror of
				https://github.com/GayPizzaSpecifications/pork.git
				synced 2025-11-03 17:39:38 +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 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()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user