Performance comparison between std::pmr containers and standard STL containers.
- C++17 compiler
- CMake 3.15+
- Python 3.8+ with pandas and matplotlib
pip install pandas matplotlib numpyWindows:
mkdir build && cd build
cmake ..
cmake --build . --config ReleaseLinux:
mkdir build && cd build
cmake ..
cmake --build . --config ReleaseWindows (automated):
.\scripts\build_and_run.ps1Windows (manual):
cd build\Release
.\benchmark_vector.exe --csv > ..\..\results\raw\vector_results.csv
.\benchmark_string.exe --csv > ..\..\results\raw\string_results.csv
.\benchmark_map.exe --csv > ..\..\results\raw\map_results.csv
.\benchmark_mixed.exe --csv > ..\..\results\raw\mixed_results.csvLinux:
cd build
./benchmark_vector --csv > ../results/raw/vector_results.csv
./benchmark_string --csv > ../results/raw/string_results.csv
./benchmark_map --csv > ../results/raw/map_results.csv
./benchmark_mixed --csv > ../results/raw/mixed_results.csvpython scripts/generate_report.py
python scripts/plot_results.pyFrom running these benchmarks:
- PMR is 3-4x slower for basic operations (vector push_back, string concat)
- PMR offers 2-3x better determinism (lower variance/CV in timing)
- Pool allocator shows best consistency (CV as low as 5.6%)
- Hard real-time systems where consistent timing beats average speed
- Embedded systems that avoid heap allocation
- Safety-critical software that needs deterministic behavior
- Short-lived operations where you know the memory limits upfront
- When you need maximum speed
- Workloads that already have consistent timing
- When timing isn't critical and performance matters most
For the full analysis and all benchmark results, check out the blog post:
PMR vs std::allocator: When 3x Slower is Better
It covers:
- Deep dive into performance numbers
- Charts showing the trade-offs
- Real code examples
- Memory resource comparisons
- Guidelines for choosing the right allocator
- Vector: push/pop, random access, sorting
- String: concatenation, copying, SSO behavior
- Map: insert/lookup/delete with int and string keys
- Mixed: sensor data collection, message queues
std::allocator- standard allocatorstd::pmr::monotonic_buffer_resource- no deallocationstd::pmr::unsynchronized_pool_resource- pooled allocation