Add timeit to measure test timings
This commit is contained in:
parent
76d9be756a
commit
492eba8f22
4 changed files with 36 additions and 14 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.4.4"
|
version = "0.5.0"
|
||||||
author = "genotrance"
|
author = "genotrance"
|
||||||
description = "C/C++ interop for Nim"
|
description = "C/C++ interop for Nim"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
@ -14,8 +14,7 @@ requires "nim >= 0.20.2", "regex >= 0.14.1", "cligen >= 0.9.45"
|
||||||
import nimterop/docs
|
import nimterop/docs
|
||||||
|
|
||||||
proc execCmd(cmd: string) =
|
proc execCmd(cmd: string) =
|
||||||
echo "execCmd:" & cmd
|
exec "tests/timeit " & cmd
|
||||||
exec cmd
|
|
||||||
|
|
||||||
proc execTest(test: string, flags = "") =
|
proc execTest(test: string, flags = "") =
|
||||||
execCmd "nim c --hints:off -f " & flags & " -r " & test
|
execCmd "nim c --hints:off -f " & flags & " -r " & test
|
||||||
|
|
@ -24,6 +23,9 @@ proc execTest(test: string, flags = "") =
|
||||||
task buildToast, "build toast":
|
task buildToast, "build toast":
|
||||||
execCmd("nim c --hints:off nimterop/toast.nim")
|
execCmd("nim c --hints:off nimterop/toast.nim")
|
||||||
|
|
||||||
|
task buildTimeit, "build timer":
|
||||||
|
exec "nim c -d:danger tests/timeit"
|
||||||
|
|
||||||
task bt, "build toast":
|
task bt, "build toast":
|
||||||
execCmd("nim c --hints:off -d:danger nimterop/toast.nim")
|
execCmd("nim c --hints:off -d:danger nimterop/toast.nim")
|
||||||
|
|
||||||
|
|
@ -34,6 +36,7 @@ task docs, "Generate docs":
|
||||||
buildDocs(@["nimterop/all.nim"], "build/htmldocs")
|
buildDocs(@["nimterop/all.nim"], "build/htmldocs")
|
||||||
|
|
||||||
task test, "Test":
|
task test, "Test":
|
||||||
|
buildTimeitTask()
|
||||||
buildToastTask()
|
buildToastTask()
|
||||||
|
|
||||||
execTest "tests/tast2.nim"
|
execTest "tests/tast2.nim"
|
||||||
|
|
@ -66,8 +69,10 @@ task test, "Test":
|
||||||
|
|
||||||
# getHeader tests
|
# getHeader tests
|
||||||
withDir("tests"):
|
withDir("tests"):
|
||||||
execCmd("nim e getheader.nims")
|
exec "nim e getheader.nims"
|
||||||
if not existsEnv("APPVEYOR"):
|
if not existsEnv("APPVEYOR"):
|
||||||
execCmd("nim e wrappers.nims")
|
exec "nim e wrappers.nims"
|
||||||
|
|
||||||
docsTask()
|
docsTask()
|
||||||
|
|
||||||
|
echo readFile("tests/timeit.txt")
|
||||||
|
|
@ -2,16 +2,11 @@ import strutils
|
||||||
|
|
||||||
proc testCall(cmd, output: string, exitCode: int, delete = true) =
|
proc testCall(cmd, output: string, exitCode: int, delete = true) =
|
||||||
var
|
var
|
||||||
ccmd =
|
ccmd = "../tests/timeit " & cmd
|
||||||
when defined(windows):
|
|
||||||
"cmd /c " & cmd
|
|
||||||
else:
|
|
||||||
cmd
|
|
||||||
|
|
||||||
if not delete:
|
if not delete:
|
||||||
ccmd = ccmd.replace(" -f ", " ")
|
ccmd = ccmd.replace(" -f ", " ")
|
||||||
|
|
||||||
echo ccmd
|
|
||||||
var
|
var
|
||||||
(outp, exitC) = gorgeEx(ccmd)
|
(outp, exitC) = gorgeEx(ccmd)
|
||||||
echo outp
|
echo outp
|
||||||
|
|
|
||||||
22
tests/timeit.nim
Normal file
22
tests/timeit.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
import std/monotimes, os, osproc, sequtils, strformat, strutils, times
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
var params = commandLineParams()
|
||||||
|
params.apply(quoteShell)
|
||||||
|
|
||||||
|
let cmd = params.join(" ")
|
||||||
|
echo &"================\nRunning: {cmd}\n"
|
||||||
|
|
||||||
|
let
|
||||||
|
|
||||||
|
start = getMonoTime()
|
||||||
|
ret = execCmd(cmd)
|
||||||
|
endt = getMonoTime()
|
||||||
|
|
||||||
|
outf = getAppDir() / "timeit.txt"
|
||||||
|
outd = if fileExists(outf): readFile(outf) else: ""
|
||||||
|
outp = &"\nRan: {cmd}\nTime taken: {$(endt - start)}\n"
|
||||||
|
|
||||||
|
echo outp
|
||||||
|
writeFile(outf, outd & outp)
|
||||||
|
quit(ret)
|
||||||
|
|
@ -9,7 +9,7 @@ withDir("wrappers"):
|
||||||
for wrapper in wrappers:
|
for wrapper in wrappers:
|
||||||
let
|
let
|
||||||
name = wrapper.extractFilename()
|
name = wrapper.extractFilename()
|
||||||
exec "git clone https://github.com/" & wrapper
|
exec "../../tests/timeit git clone https://github.com/" & wrapper
|
||||||
withDir(name):
|
withDir(name):
|
||||||
exec "nimble install -d"
|
exec "../../../tests/timeit nimble install -d"
|
||||||
exec "nimble test"
|
exec "../../../tests/timeit nimble test"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue