https://github.com/rustyconover/memory-passing-speed-benchmark
https://github.com/rustyconover/memory-passing-speed-benchmark
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/rustyconover/memory-passing-speed-benchmark
- Owner: rustyconover
- Created: 2026-01-19T16:51:17.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2026-01-19T17:51:41.000Z (6 months ago)
- Last Synced: 2026-06-09T00:34:54.805Z (about 1 month ago)
- Language: C
- Size: 23.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Memory-Passing IPC Benchmarks
A performance benchmarking suite for comparing Inter-Process Communication (IPC) mechanisms on Unix-like systems. Measures throughput trade-offs between pipes and shared memory to identify crossover points where switching IPC methods becomes worthwhile.
## Overview
This project benchmarks three IPC approaches:
| Method | Description |
|--------|-------------|
| **Pipe** | Traditional Unix pipe with producer-consumer model |
| **SHM Reused** | Single pre-allocated shared memory segment (best-case) |
| **SHM Fresh** | New shared memory allocation per message (worst-case) |
## Requirements
- macOS or Linux
- C compiler (gcc or clang)
- Python 3.6+
- matplotlib (for visualization)
## Quick Start
```bash
# Build the benchmarks
make -C src
# Run the benchmark suite
python3 run_benchmarks.py
# Analyze results
python3 analyze.py results/
```
## Usage
### Running Benchmarks
```bash
# Default run (1MB-512MB, 2000ms duration, 3 runs each)
python3 run_benchmarks.py
# Custom configuration
python3 run_benchmarks.py --sizes 1048576 4194304 16777216 --duration 5000 --runs 5
# Specific methods only
python3 run_benchmarks.py --methods pipe shm_reused
```
### Running Individual Benchmarks
```bash
# Usage:
./src/bench_pipe 4194304 2000 1 # 4MB messages for 2 seconds
./src/bench_shm_reused 16777216 2000 1
./src/bench_shm_fresh 1048576 2000 1
```
### Analyzing Results
```bash
# Generate report and visualization
python3 analyze.py results/
# Specify output path for chart
python3 analyze.py results/ --output throughput_comparison.png
```
## Project Structure
```
memory-passing/
├── src/
│ ├── bench_common.h # Shared utilities, timing, validation
│ ├── bench_pipe.c # Pipe-based IPC benchmark
│ ├── bench_shm_fresh.c # Fresh SHM allocation per message
│ ├── bench_shm_reused.c # Reused SHM benchmark
│ └── Makefile
├── run_benchmarks.py # Orchestrator script
├── analyze.py # Analysis and visualization
└── results/ # Output CSV files
```
## How It Works
### Benchmark Methodology
1. **Warmup Phase** (500ms): Stabilizes CPU and caches
2. **Measurement Phase**: Timed message passing with validation
3. **Statistics**: Computes throughput, mean, stddev, percentiles
### Message Validation
Each message includes:
- Magic number (`0xDEADBEEF`) for corruption detection
- Sequence number for order verification
- Timestamp for latency measurement
### Platform-Specific Timing
- **macOS**: `mach_absolute_time()` with timebase conversion
- **Linux**: `clock_gettime(CLOCK_MONOTONIC)`
## Output Format
Benchmark results are written as CSV:
```csv
method,msg_size,messages_per_sec,mb_per_sec,run_id
pipe,1048576,2847.32,2847.32,1
shm_reused,1048576,4521.18,4521.18,1
shm_fresh,1048576,891.45,891.45,1
```
## Sample Results
The analysis identifies crossover points where shared memory outperforms pipes:
```
=== Crossover Analysis ===
Crossover occurs between 4MB and 8MB
At sizes >= 8MB, shared memory is more efficient
=== Efficiency Ratio (SHM/Pipe) ===
1MB: 0.85x (pipe faster)
4MB: 0.97x (pipe faster)
8MB: 1.12x (shm faster)
16MB: 1.34x (shm faster)
```
## Building
```bash
cd src
make # Build all benchmarks
make clean # Remove binaries
```
The Makefile handles platform differences automatically:
- **macOS**: Uses standard POSIX SHM
- **Linux**: Links `-lrt` and `-pthread`
## License
MIT