timeit

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:

  • time : A float value representing the execution time in seconds.
  • data : The return value for the code.

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.

Return value

Returns a thing with a time and data property.

Example

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
}