Stopwatch
A POSIX C/C++ Stopwatch Library
Install / Use
/learn @MichaelDipperstein/StopwatchREADME
DESCRIPTION
This archive contains a simple and readable an POSIX C/C++ library providing basic stopwatch functionality. The library attempts to maintain microsecond accuracy for timing, but reports values in milliseconds. The actual accuracy is platform dependent.
Included in this library are two sample programs demonstrating the usage the stopwatch routines on both C and C++.
More information on this library may be found at: https://michaeldipperstein.github.io/stopwatch.html
FILES
COPYING - Rules for copying and distributing GPL software COPYING.LESSER - Rules for copying and distributing LGPL software Makefile - Makefile for this project (assumes gcc compiler and GNU make) README - this file sample.c - Sample program demonstrating usage of C stopwatch routines sample.cpp - Sample program demonstrating usage of C++ stopwatch routines stopwatch.h - Header file containing type definitions, prototypes, and a class definition to be used by programs linking to the stopwatch library stopwatch.h - C source file containing the code that implemets the stopwatch library
BUILDING
To build these files with GNU make and gcc:
- Windows users should define the environment variable OS to be Windows or Windows_NT. This is often already done.
- Enter the command "make" from the command line.
Two sample programs will be generated, sample and sample_cpp. sample verifies the C version of the stopwatch library. sample verifies the C++ version of the stopwatch library.
C USAGE
The following line declares a stopwatch data structure "stopWatch": stopwatch_t stopWatch;
The following line starts or resets a stopwatch using the data structure "stopWatch": StartTimer(&stopWatch);
The following line returns the number of milliseconds a stopwatch using the data structure "stopWatch" has been running: ReadTimer(&stopWatch);
The following line stops a stopwatch using the data structure "stopWatch" without resetting it: StopTimer(&stopWatch);
The following line restarts a stopwatch using the data structure "stopWatch", nothing will happen if the stopwatch is already running: ResumeTimer(&stopWatch);
C++ USAGE
The following line declares and initializes a stopwatch object "stopWatch": stopwatch_c stopWatch;
The following line starts or resets a stopwatch object "stopWatch": stopWatch.Start();
The following line returns the number of milliseconds a stopwatch object "stopWatch" has been running: stopWatch.Read();
The following line stops a stopwatch object "stopWatch" without resetting it: stopWatch.Stop();
The following line restarts a stopwatch object "stopWatch" nothing will happen if the stopwatch is already running: stopWatch.Resume();
HISTORY
11/07/11 - Initial release 02/08/12 - Replace gettimeofday() with clock_gettime to be resilient to time adjustments.
AUTHOR
Michael Dipperstein (mdipperstein@gmail.com)
Related Skills
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
