Mistake on this page?
Report an issue in GitHub or email us

Timer

Timer class hierarchy

Use the Timer interface to create, start, stop and read a stopwatch-like timer for measuring precise times (better than millisecond precision).

You can independently create, start and stop any number of Timer objects.

Warnings and notes

  • Timers are based on 64-bit signed microsecond counters, giving a range of over 250,000 years.
  • While a Timer is running, deep sleep is blocked to maintain accurate timing. If you don't need microsecond precision, consider using the LowPowerTimer or Kernel::Clock classes instead because these do not block deep sleep mode.

Timer class reference

Timer hello, world

/*
 * Copyright (c) 2006-2020 Arm Limited and affiliates.
 * SPDX-License-Identifier: Apache-2.0
 */
#include "mbed.h"

using namespace std::chrono;

Timer t;

int main()
{
    t.start();
    printf("Hello World!\n");
    t.stop();
    printf("The time taken was %llu milliseconds\n", duration_cast<milliseconds>(t.elapsed_time()).count());
}

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.