Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unregulated-cpp20 #30

Merged
merged 10 commits into from Aug 8, 2022
Merged

Add unregulated-cpp20 #30

merged 10 commits into from Aug 8, 2022

Conversation

wx257osn2
Copy link
Contributor

@wx257osn2 wx257osn2 commented Aug 2, 2022

現行のC++版をベースにして,極力標準ライブラリを使用する,というレギュレーションを外してみた(外部ライブラリを積極的に採用した)バージョンです(現行の cpp とは別に追加しています).ある種の参考にはなるかと思いますがレギュレーションを意識して破っているという点で公平さには欠けるため,ベンチマークに含める(マージする)かどうかは思索ください.主要な変更点として

  • コンパイラを g++
    • 以下の fast_iog++ の方が性能が出やすいため
  • 入出力にfast_ioを使用
    • C++20向けの高速IOライブラリ
  • debug の分岐に [[unlikely]] を付記
    • 通常実行時には通らない実行パスなので,事前に分岐予測を与えることで僅かに速度が向上する
  • コンテナを標準ライブラリの std::vector からBoost.Containerのものへ変更
    • boost::container::vector はコンテナ伸長時のreallocationに realloc 相当の機能を使うことで要素の移し替えコストの削減が期待できます.
    • boost::container::small_vector は指定した要素数まではメモリ確保無しに(自身のメンバとして直接)値を保持します.
      • 今回であれば boost::container::vector の要素として大量の boost::container::small_vector を使用しているため,通常の std::vectorboost::container::vector などと比べてメモリのローカリティが大幅に上がり,キャッシュヒット率の向上が期待できます.
      • これはデータセットに依存するのですが,今回のベンチマークで使っているデータセットだとノードから出るエッジの数は4本以下であることが殆どであるため, 4 を指定することで非常に高い実行効率を得られます.
$ uname -a
Linux HOSTNAME 5.13.0-28-generic #31~20.04.1-Ubuntu SMP Wed Jan 19 14:08:10 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ cat /proc/cpuinfo | grep name
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
model name      : Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz
$ g++ --version
g++ (Ubuntu 11.1.0-1ubuntu1~20.04) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ clang++ --version
Ubuntu clang version 12.0.0-3ubuntu1~20.04.4
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ ./run.sh cpp cpp20
Building cpp...
~/langs-bench-dijkstra/cpp ~/langs-bench-dijkstra
rm -f main
clang++ -std=c++17 -O3 -Wall -Wextra -pedantic-errors -march=native -mtune=native -I external_projects/unordered_dense/include -o main src/main.cpp
~/langs-bench-dijkstra

Building cpp20...
~/langs-bench-dijkstra/cpp20 ~/langs-bench-dijkstra
rm -f main
g++ -std=c++20 -O3 -Wall -Wextra -pedantic-errors -march=native -mtune=native -I external_projects/unordered_dense/include -I external_projects/fast_io/include -DFAST_IO_OPTIMIZE_SIZE -I external_projects/container/include -I external_projects/move/include -I external_projects/intrusive/include -I external_projects/config/include -I external_projects/assert/include -I external_projects/static_assert/include -I external_projects/core/include -Wno-stringop-overread -o main src/main.cpp
~/langs-bench-dijkstra

Benchmark 1: cd cpp; ./bench.sh 0 < ../data/Tokyo_Edgelist.csv
  Time (mean ± σ):     152.9 ms ±   3.1 ms    [User: 137.8 ms, System: 15.0 ms]
  Range (min … max):   150.4 ms … 164.7 ms    19 runs

Benchmark 2: cd cpp20; ./bench.sh 0 < ../data/Tokyo_Edgelist.csv
  Time (mean ± σ):     117.1 ms ±   1.5 ms    [User: 95.2 ms, System: 21.8 ms]
  Range (min … max):   115.3 ms … 121.5 ms    25 runs

Summary
  'cd cpp20; ./bench.sh 0 < ../data/Tokyo_Edgelist.csv' ran
    1.31 ± 0.03 times faster than 'cd cpp; ./bench.sh 0 < ../data/Tokyo_Edgelist.csv'
Benchmark 1: cd cpp; ./bench.sh 20 < ../data/Tokyo_Edgelist.csv
  Time (mean ± σ):      1.129 s ±  0.036 s    [User: 1.110 s, System: 0.019 s]
  Range (min … max):    1.067 s …  1.171 s    10 runs

Benchmark 2: cd cpp20; ./bench.sh 20 < ../data/Tokyo_Edgelist.csv
  Time (mean ± σ):     690.9 ms ±  15.5 ms    [User: 666.5 ms, System: 24.3 ms]
  Range (min … max):   676.2 ms … 726.3 ms    10 runs

Summary
  'cd cpp20; ./bench.sh 20 < ../data/Tokyo_Edgelist.csv' ran
    1.63 ± 0.06 times faster than 'cd cpp; ./bench.sh 20 < ../data/Tokyo_Edgelist.csv'

@reki2000
Copy link
Owner

reki2000 commented Aug 8, 2022

ありがとうございます。試してみましたが明らかに高速になっていますね!

レギュレーション違反というのも言語によってどこまで外部ライブラリを認めるかばらつきはありますが、これを突き詰めるとチューンされた外部ライブラリが多ければ多いほど早くなるので、言語間の比較としてはご指摘の通り少し意図とずれてくるという認識です。ただ、「何をやってもいいのでこのベンチのデータ構造・アルゴリズムでの最速実装」というものがあっても良いとは思います。

以下を対応いただければマージしようと思いますが、いかがでしょうか。

  • ディレクトリ名を unregulated-cpp20 にする
  • readmeの Submodules are contained の前に "For cpp and unregulated-cpp20," を追加 ※依存する外部リポジトリがかなり量が増えているので

@wx257osn2
Copy link
Contributor Author

@reki2000 対応しました!

@wx257osn2 wx257osn2 changed the title Add cpp20 Add unregulated-cpp20 Aug 8, 2022
@reki2000 reki2000 merged commit 09a350d into reki2000:master Aug 8, 2022
@wx257osn2 wx257osn2 deleted the add-cpp20 branch August 9, 2022 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants