aboutsummaryrefslogtreecommitdiff
path: root/tests/timeit.nim
blob: cf9417f0d4bc69035ad087f789fe656bed3354c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os, osproc, sequtils, strformat, strutils, times

when (NimMajor, NimMinor) >= (1, 0):
  import std/monotimes

  template getTime(): MonoTime = getMonoTime()
else:
  template getTime(): float = epochTime()

when isMainModule:
  var params = commandLineParams()
  params.apply(quoteShell)

  let cmd = params.join(" ")
  echo &"================\nRunning: {cmd}\n"

  let

    start = getTime()
    ret = execCmd(cmd)
    endt = getTime()

    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 mod 255)