Hello,
I'm new to Nim and I'm trying to learn it by doing and currently working with HttpClient and I'm trying to port some of my simple Python tools to Nim just for fun and wondering if anyone knows how to get total request time in Nim? I have a tool which does some API calls and rapports back response and total time in Python and for learning purposes, I want to try to port it to Nim but I'm struggling with this particular problem. Could anyone help me with that?
Thanks!
timeit(100): # Python-like timeit.timeit("code_to_benchmark", number=int)
sleep(9) # Repeats this code 100 times. Output is very informative.
sleep(9) is like your code with the task to measure. Prints something like:
2020-06-17T21:59:09+03:00 TimeIt: 100 Repetitions on 927 milliseconds, 704 microseconds, and 816 nanoseconds, CPU Time 0.0007382400000000003.
include prelude
let t0 = cpuTime()
code_here() # Code here
echo t0 - cpuTime()
If you just want to time a request call:
import httpclient, times
let startTime = epochTime()
var client = newHttpClient()
echo client.getContent("http://google.com")
echo "took: ", epochTime() - startTime, "s"