- C++(
std::vector/std::deque/std::list)と Rust(Vec/VecDeque/LinkedList)で同一ワークロードを実行し、主要コンテナの性能を比較。 - コピー性能・シーケンシャル読み取り・統計量(平均・分散)を測定して、振る舞いを定量的に把握します。
- 単一の
Makefileでmainバイナリを C++ / Rust いずれからでも生成可能。
- ツールチェーン: C++17 対応コンパイラ(g++ / clang++)と Rust stable (
rustc) を用意。 - 取得:
git clone <repo-url> cd container-benchmark
- ベンチマーク実行:
make cpp-bench # C++ 版ビルド & 実行 make rust-bench # Rust 版ビルド & 実行
- 各ターゲットは
build/<lang>/mainを生成し、最後に./mainを上書きします。
- 各ターゲットは
- クリーンアップ:
make clean
vector_deque_list.cpp— C++17 実装。設定値はBenchmarkConfigに集約。vector_deque_list.rs— Rust 実装。configモジュール内で設定を管理し、std::hint::black_boxで読み取り最適化を防止。Makefile—cpp-bench/rust-bench/cleanターゲットを定義。build/— ビルド結果を保持(初回実行時に作成)。
- コピー: 共通データから各コンテナへ投入し、割り当て動作を比較。
- シーケンシャル読み取り:
READ_REPEAT_COUNT回ループしつつi64に加算、black_boxでコード除去を防止。 - 統計量: 平均と分散を計算し、イテレータコストを評価。
- 表示: 先頭
DISPLAY_COUNT件と経過時間(ミリ秒)をすべて出力。
- データサイズ: C++ は
BenchmarkConfig::Size、Rust はELEMENT_COUNTを調整。 - 乱数範囲: C++ の
MinRandomValue/MaxRandomValue、Rust のRANDOM_MIN/RANDOM_MAXを更新。 - ビルドフラグ:
Makefile内のg++/rustc呼び出しを編集して最適化レベルや警告を変更。
| ターゲット | 説明 |
|---|---|
make / make all |
cpp-bench → rust-bench の順に実行 |
make cpp-bench |
C++ 版をビルド・実行(成果物: build/cpp/main) |
make rust-bench |
Rust 版をビルド・実行(成果物: build/rust/main) |
make clean |
build/ と ./main を削除 |
注意: 両言語のバイナリが必要な場合は
build/cpp/mainとbuild/rust/mainを直接利用してください。
- ミリ秒が小さいほど高速。コンテナ間および言語間で比較。
Vec/vectorとLinkedListの差はキャッシュヒット率やポインタ追跡コストの影響が大きい。- Rust : 読み取り結果が
0.00 msになる場合は最新版に更新し、black_boxが効いているか確認。
- コンパイラが見つからない:
g++/rustcが PATH にあるか確認し、必要ならインストール。 - メモリ不足:
Size/ELEMENT_COUNTを小さくする。 - 乱数を固定したい: 両言語ともにシードを固定値へ変更。
MIT License(詳細は LICENSE.md を参照)。
- Compare
std::vector,std::deque,std::listwithVec,VecDeque,LinkedListunder identical workloads. - Measure copy throughput, sequential reads, and statistics to understand trade-offs.
- Ship a single Makefile so
maincan be produced from either toolchain with consistent flags.
- Toolchains: Install a C++17 compiler (g++/clang++) and Rust stable (
rustc). - Clone:
git clone <repo-url> cd container-benchmark
- Run benchmarks:
make cpp-bench make rust-bench
- Each target writes to
build/<lang>/mainand copies the binary to./main.
- Each target writes to
- Cleanup:
make clean
vector_deque_list.cpp— C++17 implementation withBenchmarkConfig.vector_deque_list.rs— Rust implementation; configuration lives inconfig; sequential reads callstd::hint::black_box.Makefile— Definescpp-bench,rust-bench,clean.build/— Generated on demand to store compiled binaries.
- Copy — Load each container from the shared dataset to highlight allocation behaviour.
- Sequential read — Iterate
READ_REPEAT_COUNTtimes, summing intoi64while preventing optimisation removal. - Statistics — Compute mean and variance to expose traversal overhead.
- Output — Print elapsed milliseconds plus the first
DISPLAY_COUNTelements for sanity checks.
- Workload size — Edit
BenchmarkConfig::Size(C++) orELEMENT_COUNT(Rust). - Random range — Adjust
MinRandomValue/MaxRandomValueorRANDOM_MIN/RANDOM_MAX. - Build flags — Modify the
g++/rustccommands inMakefileto experiment with optimisation levels or warnings.
| Target | Description |
|---|---|
make / make all |
Run cpp-bench then rust-bench. |
make cpp-bench |
Build & execute the C++ benchmark (build/cpp/main). |
make rust-bench |
Build & execute the Rust benchmark (build/rust/main). |
make clean |
Remove build/ and ./main. |
Note: To keep both binaries, use the files under
build/cpp/andbuild/rust/directly.
- Lower milliseconds imply faster operations; compare across containers and languages.
- Large gaps between
Vec/vectorandLinkedListoften stem from cache locality and pointer traversal. - Rust : If you still observe
0.00 mssequential reads, rebuild to ensure theblack_boxupdates are applied.
- Compiler missing — Verify
g++andrustcexist on thePATH; install via your package manager orrustup. - High memory usage — Reduce the element counts.
- Deterministic RNG — Replace the dynamic seeds with fixed values in both sources.
Distributed under the MIT License (LICENSE.md).