Skip to content

tisaac/tictoc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TicTocTimer

A high-resolution timer for Windows, OS X, and Linux.

Performance timers are useful for profiling and optimizing code, but using one typically involves system specific calls. So, I wrapped these up and put them behind a simple API.

Incorporating into your project

  • Either build and link against the static library.
  • Or just copy tictoc.[ch] to your project.
  • On linux, you'll need to link against librt.

With CMake:

Unpack the source tree (or use git submodule) to a subdirectory in your project. For example, modules/tictoc.

  add_subdirectory(modules/tictoc) #adds targets for the static library, tests, and docs
  link_directories(${tictoc_BINARY_DIR})
  include_directories(modules/tictoc)
  ...
  target_link_libraries(my-project tictoc)

Usage

Simple example:

#include "tictoc.h"
int main(int argc, char* argv[])
{ 
  TicTocTimer clock = tic();
  time_consuming_operation();
  printf("Elapsed time %f seconds.\n",toc(&clock)); // prints time since last tic()  
  another_time_consuming_operation();
  printf("Elapsed time %f seconds.\n",toc(&clock)); // prints time since last toc()
}

An even simpler example:

#include "tictoc.h"
int main(int argc, char* argv[])
{ 
  tic();
  printf("%f\n",toc(0));
}

The last example uses a global timer. Using the global timer from different threads may produce strange results.

Reliability

The test suite runs tests for different resolutions that rely on some implementation of usleep() to pause for semi-controlled lengths of time. However, this isn't a reliable way to measure the actual precision of your system's timer.

You'll have to measure that for yourself according to what is appropriate for your application.

Details

About

High-resolution timer for Windows, OSX, and Linux

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 54.0%
  • CMake 29.5%
  • C++ 16.5%