Created
June 15, 2020 19:55
-
-
Save lonesometraveler/ba3ed55fe0490461a72b74ddc1959e70 to your computer and use it in GitHub Desktop.
[mbed OS6] elapsed time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mbed.h" | |
int main() { | |
Timer t; | |
t.start(); | |
ThisThread::sleep_for(1s); | |
t.stop(); | |
auto f = chrono::duration<float>(t.elapsed_time()).count(); | |
auto s = chrono::duration_cast<chrono::seconds>(t.elapsed_time()).count(); | |
auto ms = chrono::duration_cast<chrono::milliseconds>(t.elapsed_time()).count(); | |
auto us = t.elapsed_time().count(); | |
printf ("Timer time: %f s\n", f); | |
printf ("Timer time: %llu s\n", s); | |
printf ("Timer time: %llu ms\n", ms); | |
printf ("Timer time: %llu us\n", us); | |
} | |
// Timer time: 1.002245 s | |
// Timer time: 1 s | |
// Timer time: 1002 ms | |
// Timer time: 1002245 us |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment