Skip to content

Instantly share code, notes, and snippets.

@lonesometraveler
Created June 15, 2020 19:55
Show Gist options
  • Save lonesometraveler/ba3ed55fe0490461a72b74ddc1959e70 to your computer and use it in GitHub Desktop.
Save lonesometraveler/ba3ed55fe0490461a72b74ddc1959e70 to your computer and use it in GitHub Desktop.
[mbed OS6] elapsed time
#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