• If you like to check the runtime of you code you can use something like this:

    var t1, t2;
    t1 = Date.now()
    //begin code to messure
    a = analogRead(D28);
    // end code to messuere
    t2 = Date.now()
    print("runtime:", t2-t1);
    /* output
    runtime: 0.88500976562
    */
    

    Are this 0.885 mili seconds or 0.885 micro second

    Reference say:

    Get the number of milliseconds elapsed since 1970 (or on embedded platforms, since startu)

    So the difference should be micro seconds. Not shure because a output of Date.now() looks like this 41866529.26635742187.

  • Reference say: "Get the number of milliseconds" So the difference should be micro seconds.

    why milli-milli=micro?

    Not shure because a output of Date.now() looks like this 41866529.26635742187.

    Still it can be milli but with fraction

    BTW there is also getTime() - similar but in seconds with fraction

    EDIT: what is a bit strange is that in Bangle 2 emulator Date.now() has no fraction

  • what is a bit strange is that in Bangle 2 emulator Date.now() has no fraction

    Yes... If I recall the JS spec says that Date.now() should be a whole number. But since we usually keep track of time to finer accuracy than that it felt like it would have been a mistake to deliberately throw away info just to make it look like desktop JS.

    On the emulator Date.now() is only giving us time accurate to 1ms so that's all we give.

  • Ok, so it's 0.885 ms - Thanks

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Which unit has the difference of two Date.now() calls?

Posted by Avatar for MaBe @MaBe

Actions