A time-based queue where the length of the queue is a duration, divided into buckets based on a given time interval. As time progresses, buckets in the past are cleared, and the main queue is updated so that the front only returns a valid object that has not expired. To improve performance, buckets are only cleared on push or pop operations. Buckets in the past can therefore be cleared in bulk based on how many intervals have elapsed since the last update.
timeq is a header-only C++20 library. The public API lives under include/timeq/.
- CMake 3.13 or newer
- A C++20 compiler (GCC, Clang, or Apple Clang)
When built as the top-level project, test and benchmark dependencies (GoogleTest and Google Benchmark) are fetched automatically via CPM.cmake.
Configure a build directory:
cmake -B build -DCMAKE_BUILD_TYPE=ReleaseCompile:
cmake --build build -j| Option | Default (top-level) | Description |
|---|---|---|
BUILD_TESTING |
ON |
Enable CTest integration |
timeq_BUILD_TESTS |
ON |
Build the GoogleTest suite |
timeq_BUILD_BENCHMARKS |
ON |
Build the Google Benchmark executable |
To configure without tests or benchmarks:
cmake -B build -DBUILD_TESTING=OFFOr disable them individually:
cmake -B build -Dtimeq_BUILD_TESTS=OFF -Dtimeq_BUILD_BENCHMARKS=OFFNote
When timeq is added as a subdirectory of another CMake project, tests and
benchmarks are disabled by default.
cmake --install build --prefix /path/to/installThis installs the headers and CMake target for use from other projects.
Tests are built when BUILD_TESTING and timeq_BUILD_TESTS are enabled (the default
when configuring this repository directly).
Run the full suite with CTest:
ctest --test-dir build --output-on-failureOr run the test binary directly:
./build/tests/timeq_testFor a single test case:
./build/tests/timeq_test --gtest_filter=time_queue.PushAndExpireBenchmarks are built when BUILD_TESTING and timeq_BUILD_BENCHMARKS are enabled.
Use a Release build for meaningful results.
Run all benchmarks:
./build/benchmark/timeq_benchmarkRun a subset by name filter:
./build/benchmark/timeq_benchmark --benchmark_filter=BM_TimeQueue_PushUseful Google Benchmark flags:
# Repeat each benchmark and report statistics
./build/benchmark/timeq_benchmark --benchmark_repetitions=5
# Set a minimum run time (seconds) per benchmark
./build/benchmark/timeq_benchmark --benchmark_min_time=1The benchmark suite covers construction, push, pop, pop-front, and mixed push/pop workloads at different queue sizes and bucket intervals.