A comprehensive benchmarking suite for comparing the performance of common data structures in C++. Now cross-platform compatible (Windows, macOS, Linux).
This project provides an empirical analysis of time complexity and RAM usage for common operations across six fundamental data structures:
- Array
- Stack
- Queue
- Binary Search Tree (BST)
- Linked List
- Max Heap
Each data structure is tested for various operations to help developers understand real-world performance implications beyond theoretical time complexity.
- Cross-Platform Support: Works on Windows, macOS, and Linux
- Standardized Testing Framework: All data structures are tested under identical conditions
- Comprehensive Operation Testing:
- Creation of new instances
- Deletion of prefilled instances
- Adding elements to empty structures
- Adding elements to prefilled structures
- Removing elements from structures
- Calculating averages of elements
- Dual Benchmarking: Measure both time complexity and RAM usage
- Statistical Validity: Each operation is tested multiple times (default: 1000) to ensure reliable results
- Easy Comparison: Results are displayed in a consistent format for simple comparison
Compile the project using g++:
g++ -o benchmark main.cpp structures/array.cpp structures/linkedlist.cpp structures/queue.cpp structures/timer.cpp structures/bintree.cpp structures/maxheap.cpp structures/stack.cppg++ -o benchmarkRAM mainRAM.cpp structures/array.cpp structures/linkedlist.cpp structures/queue.cpp structures/timer.cpp structures/bintree.cpp structures/maxheap.cpp structures/stack.cppRun the compiled executables:
# Time benchmarks
./benchmark
# RAM usage benchmarks
./benchmarkRAMThe programs will run all tests and display performance metrics for each operation on each data structure.
- Test Units: 1000 iterations per operation (configurable)
- Prefill Size: 12 elements (configurable)
- Random Values: Float values between 0 and 100
- Time benchmarks: Results are reported as average execution times in milliseconds (scaled by 100000 for precision). Lower values indicate better performance.
- RAM benchmarks: Results show memory usage before and after operations in bytes (B). Lower differences indicate better memory efficiency.
├── main.cpp # Time performance benchmarking
├── mainRAM.cpp # RAM usage benchmarking
├── structures/
│ ├── array.h/cpp # Dynamic array implementation
│ ├── bintree.h/cpp # Binary search tree implementation
│ ├── linkedlist.h/cpp # Linked list implementation
│ ├── maxheap.h/cpp # Max heap implementation
│ ├── queue.h/cpp # Queue implementation
│ ├── stack.h/cpp # Stack implementation
│ └── timer.h/cpp # Cross-platform timer utility
├── analysis.xlsx # Performance analysis results
└── README.md # Project documentation
This project is designed to work across multiple platforms:
- Windows: Full support for both time and RAM benchmarks
- macOS: Full support using Mach kernel APIs for memory measurement
- Linux: Full support using POSIX APIs (can be extended)
The codebase uses conditional compilation (#ifdef _WIN32) to provide platform-specific implementations where needed.
Contributions are welcome! Consider adding:
- Additional data structures
- More test cases
- Visualization of results
- Performance optimization tips based on results