mywheel-rs

Performance Comparison: mywheel-rs vs std::collections

This document provides performance comparisons between the custom data structures in mywheel-rs and their equivalent standard library implementations.

Summary Table

Structure Time Complexity Space Complexity Memory Usage Cache Performance Best Use Cases
Dllist O(1) operations O(n) total O(1) per node Poor Low-overhead linking, FM algorithms
std::LinkedList O(1) operations O(n) total O(1) per node Poor General purpose
BPQueue O(1) insert/delete, O(log k) extract O(k + n) total O(k) buckets Excellent Bounded integer keys, scheduling
std::BinaryHeap O(log n) insert, O(log n) extract O(n) total O(n) total Good General priority queue
RepeatArray O(1) access O(1) total O(1) total Excellent Constant data, large arrays
ShiftArray O(1) access, O(n) iteration O(n) total O(n) total Good Sliding windows, circular buffers
MapAdapter O(1) access O(n) total O(n) total Good Vector-like access, sparse data
std::Vec O(1) access O(n) total O(n) total Excellent General purpose

Detailed Analysis

Dllist vs std::LinkedList

Advantages of Dllist:

Advantages of std::LinkedList:

When to use Dllist:

When to use std::LinkedList:

BPQueue vs std::BinaryHeap

Advantages of BPQueue:

Advantages of std::BinaryHeap:

When to use BPQueue:

When to use std::BinaryHeap:

Array Structures vs std::Vec

RepeatArray Advantages:

RepeatArray Disadvantages:

ShiftArray Advantages:

ShiftArray Disadvantages:

When to use RepeatArray:

When to use ShiftArray:

When to use std::Vec:

MapAdapter vs std::Vec

MapAdapter Advantages:

MapAdapter Disadvantages:

When to use MapAdapter:

When to use std::Vec:

Robin vs Custom Scheduling

Robin Advantages:

Robin Limitations:

When to use Robin:

When to use custom scheduling:

Benchmarks Summary

Based on the benchmarks in benches/benches.rs, here are key findings:

Dllist Performance:

BPQueue Performance:

Array Performance:

Recommendations

For High-Performance Systems:

  1. Use BPQueue for bounded integer priority queues
  2. Use RepeatArray for large constant datasets
  3. Use Dllist when nodes must be shared between structures
  4. Consider cache locality in data structure design

For Memory-Constrained Systems:

  1. Use RepeatArray for constant data (100x memory reduction)
  2. Use MapAdapter for sparse data representations
  3. Prefer array-based structures over linked structures when possible

For General Purpose Applications:

  1. Use std::Vec for flexibility and simplicity
  2. Use std::BinaryHeap for general priority queues
  3. Use std::LinkedList for simple linked list needs
  4. Consider custom structures only when specific performance advantages are needed

This comparison should help you choose the right data structure for your specific use case and performance requirements.