Skip to content

Saptarshi-max/pmr-benchmark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PMR vs STD Containers Benchmark

Performance comparison between std::pmr containers and standard STL containers.

Requirements

  • C++17 compiler
  • CMake 3.15+
  • Python 3.8+ with pandas and matplotlib
pip install pandas matplotlib numpy

Build

Windows:

mkdir build && cd build
cmake ..
cmake --build . --config Release

Linux:

mkdir build && cd build
cmake ..
cmake --build . --config Release

Run

Windows (automated):

.\scripts\build_and_run.ps1

Windows (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.csv

Linux:

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.csv

Generate Reports

python scripts/generate_report.py
python scripts/plot_results.py

Key Findings

From running these benchmarks:

Performance Trade-offs

  • 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%)

When to Use PMR

  • 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 to Use std::allocator

  • When you need maximum speed
  • Workloads that already have consistent timing
  • When timing isn't critical and performance matters most

Blog Post

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

What's Tested

  • 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

Memory Resources

  • std::allocator - standard allocator
  • std::pmr::monotonic_buffer_resource - no deallocation
  • std::pmr::unsynchronized_pool_resource - pooled allocation

About

This repository contains a focused benchmark suite comparing standard STL containers with their std::pmr polymorphic‑allocator equivalents. It provides reproducible experiments, scripts, and plots that measure allocation behavior, throughput, and memory‑management overhead across differnt workloads.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors