The timeit function can be used to check the duration of some code. It only measures the execution time of the code and does not include additional change creation and does not wait for futures to be completed. The function accepts any code and returns with a new thing with two properties:
It is (almost) a shortcut for the following ThingsDB code:
_timeit = |code| {
start = now();
data = code();
time = now() - start;
{
time:,
data:,
};
};
// example usage:
_timeit(|| {
// code to time
2 + 2;
});
This function does not generate a change.
Returns a thing with a time and data property.
This code shows an example for timeit():
timeit({
range(1, 11).map(|x| `{x} x 7 = {x*7}`); // generates table of seven
});
Example return value:
{
"data": [
"1 x 7 = 7",
"2 x 7 = 14",
"3 x 7 = 21",
"4 x 7 = 28",
"5 x 7 = 35",
"6 x 7 = 42",
"7 x 7 = 49",
"8 x 7 = 56",
"9 x 7 = 63",
"10 x 7 = 70"
],
"time": 0.000057546
}