Commit 6ec604b7 authored by Kunshan Wang's avatar Kunshan Wang

Small timing test

parent cd3dd7d8
package junks
import uvm.refimpl.MicroVM
import uvm.refimpl.VMConf
import uvm.GlobalBundle
import uvm.TrantientBundle
import uvm.utils.IDFactory
import uvm.ir.textinput.UIRTextReader
import java.io.Reader
import java.io.StringReader
import java.io.StringWriter
import uvm.ir.textoutput.BundleSerializer
import org.slf4j.LoggerFactory
import com.typesafe.scalalogging.Logger
import uvm.testutil.StopWatch
object DumpLoadTimer extends App {
val logger = Logger(LoggerFactory.getLogger(getClass.getName))
def parseReader(reader: Reader, globalBundle: GlobalBundle, fac: Option[IDFactory] = None): TrantientBundle = {
val idf = fac.getOrElse(new IDFactory(uvm.refimpl.MicroVM.FIRST_CLIENT_USABLE_ID))
val r = new UIRTextReader(idf, recordSourceInfo = false)
val ir = r.read(reader, globalBundle)
ir
}
def parseFile(fileName: String, globalBundle: GlobalBundle, fac: Option[IDFactory] = None): TrantientBundle = {
parseReader(new java.io.FileReader(fileName), globalBundle, fac)
}
// Replace this with a big UIR bundle
val fileName = "/Users/wks/junk/RPySOM-no-jit.uir"
def main(): Unit = {
val w = new StopWatch()
w.start()
val gb = new GlobalBundle()
logger.info("Parsing (fresh) %s ...".format(fileName))
val tb = parseFile(fileName, gb)
gb.merge(tb)
val s1 = w.split()
logger.info("Dumping loaded bundle...")
val sw = new StringWriter()
val bs = new BundleSerializer(gb, None)
bs.writeUIR(sw)
val bTxt = sw.toString()
logger.debug("Bundle dumped.")
//logger.debug("Bundle:\n" + bTxt)
val s2 = w.split()
val gb2 = new GlobalBundle()
val sr = new StringReader(bTxt)
logger.info("Load bundle again ...".format(fileName))
val tb2 = parseReader(sr, gb2)
gb2.merge(tb2)
val s3 = w.stop()
val total = w.total()
logger.info("load1: %d, dump: %d, load2: %d, total: %d".format(s1,s2,s3,total))
}
main()
}
\ No newline at end of file
package uvm.testutil
object StopWatch {
def measureTime(f: => Unit): Long = {
val t1 = System.nanoTime()
f
val t2 = System.nanoTime()
t2 - t1
}
}
class StopWatch {
var startTime: Long = _
var lastSplit: Long = _
var stopTime: Long = _
def start(): Unit = {
val t = System.nanoTime()
startTime = t
lastSplit = t
}
def split(): Long = {
val t = System.nanoTime()
val result = t - lastSplit
lastSplit = t
result
}
def stop(): Long = {
val t = System.nanoTime()
val result = t - lastSplit
lastSplit = t
stopTime = t
result
}
def total(): Long = {
stopTime - startTime
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment