added cpuTime to VM (#12346)

* added cpuTime to VM

* Hide VM-time cpuTime() behind --benchmarkVM flag
This commit is contained in:
Ico Doornekamp 2019-10-04 19:32:16 +02:00 • committed by Andreas Rumpf
commit 26676066cc
4 changed files with 14 additions and 0 deletions

View file

@ -792,6 +792,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
discard "the default" discard "the default"
else: else:
localError(conf, info, "unknown Nim version; currently supported values are: {1.0}") localError(conf, info, "unknown Nim version; currently supported values are: {1.0}")
of "benchmarkvm":
processOnOffSwitchG(conf, {optBenchmarkVM}, arg, pass, info)
of "": of "":
conf.projectName = "-" conf.projectName = "-"
else: else:

View file

@ -84,6 +84,7 @@ type # please make sure we have under 32 options
optNimV2 optNimV2
optMultiMethods optMultiMethods
optNimV019 optNimV019
optBenchmarkVM # Enables cpuTime() in the VM
TGlobalOptions* = set[TGlobalOption] TGlobalOptions* = set[TGlobalOption]

View file

@ -16,6 +16,7 @@ from math import sqrt, ln, log10, log2, exp, round, arccos, arcsin,
from os import getEnv, existsEnv, dirExists, fileExists, putEnv, walkDir, getAppFilename from os import getEnv, existsEnv, dirExists, fileExists, putEnv, walkDir, getAppFilename
from md5 import getMD5 from md5 import getMD5
from sighashes import symBodyDigest from sighashes import symBodyDigest
from times import cpuTime
from hashes import hash from hashes import hash
@ -25,6 +26,9 @@ template mathop(op) {.dirty.} =
template osop(op) {.dirty.} = template osop(op) {.dirty.} =
registerCallback(c, "stdlib.os." & astToStr(op), `op Wrapper`) registerCallback(c, "stdlib.os." & astToStr(op), `op Wrapper`)
template timesop(op) {.dirty.} =
registerCallback(c, "stdlib.times." & astToStr(op), `op Wrapper`)
template systemop(op) {.dirty.} = template systemop(op) {.dirty.} =
registerCallback(c, "stdlib.system." & astToStr(op), `op Wrapper`) registerCallback(c, "stdlib.system." & astToStr(op), `op Wrapper`)
@ -194,3 +198,9 @@ proc registerAdditionalOps*(c: PCtx) =
registerCallback c, "stdlib.hashes.hashVmImplByte", hashVmImplByte registerCallback c, "stdlib.hashes.hashVmImplByte", hashVmImplByte
registerCallback c, "stdlib.hashes.hashVmImplChar", hashVmImplByte registerCallback c, "stdlib.hashes.hashVmImplChar", hashVmImplByte
if optBenchmarkVM in c.config.globalOptions:
wrap0(cpuTime, timesop)
else:
proc cpuTime(): float = 5.391245e-44 # Randomly chosen
wrap0(cpuTime, timesop)

View file

@ -129,3 +129,4 @@ Advanced options:
--profiler:on|off enable profiling; requires `import nimprof`, and --profiler:on|off enable profiling; requires `import nimprof`, and
works better with `--stackTrace:on` works better with `--stackTrace:on`
see also https://nim-lang.github.io/Nim/estp.html see also https://nim-lang.github.io/Nim/estp.html
--benchmarkVM:on|off enable benchmarking of VM code with cpuTime()