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

C++実装のリファクタリング/高速化(again) #9

Merged
merged 6 commits into from Jun 23, 2020

Conversation

wx257osn2
Copy link
Contributor

@wx257osn2 wx257osn2 commented Jun 22, 2020

レギュレーションの変更(ダイクストラ法の修正)に伴ってRustより遅くなったので

変更点

  • リファクタリング
    • Distancestd::int32_t
    • INT32_MAXstd::numeric_limits<Distance>::max()
      • 将来 Distancestd::int64_t にすることがあっても勝手に INT64_MAX を引いてくれます. そんな変更する予定一切無いでしょうが…
    • std::vector のfillをコンストラクタで行うように変更
  • 高速化
    • 変数の初期化を除去
      • 想定する入力が来ると仮定して良い場合,初期化しても上書きされるので不要です
    • line[pos] == '\r' の条件式を削除
      • 直前の while (!isgraph(line.back())) line.pop_back(); で行末の '\r' は除去されているため,この条件式が true になるのは行の途中に出てきたときだけです(そしてそのような入力は想定していないと思います)
    • ハッシュマップの実装を robin-hood-hashing に変更
      • @mitsutaka-takeda さんのアイデアを反映(https://github.com/mitsutaka-takeda/langs-bench-dijkstra)
      • Rustも標準ライブラリ外のハッシュ実装を使っているので,C++も使って良いのではないかと思います.
      • git submoduleを使うようにしたので,READMEに「git submodule update --init 忘れないでね」の文言を追加

実行結果

実行環境は #4 と同様です.

Rust(10b505d):

  Time (mean ± σ):      1.439 s ±  0.008 s    [User: 1.424 s, System: 0.014 s]
  Range (min … max):    1.424 s …  1.448 s    10 runs

C++(10b505d):

  Time (mean ± σ):      1.543 s ±  0.007 s    [User: 1.525 s, System: 0.017 s]
  Range (min … max):    1.535 s …  1.555 s    10 runs

C++(4f9c518):

  Time (mean ± σ):      1.343 s ±  0.007 s    [User: 1.322 s, System: 0.021 s]
  Range (min … max):    1.332 s …  1.355 s    10 runs

Rustに勝ちました. 多分これが一番速いと思います

@reki2000 reki2000 marked this pull request as ready for review June 23, 2020 00:39
@reki2000
Copy link
Owner

@wx257osn2 いつも興味深いPRありがとうございます。
もともとのベンチの目的はあらかた達成できた中、特にトップ争いとしては別の面白さもありますので、独自ライブラリいれるのもありということにします

@reki2000 reki2000 merged commit 5b9cefb into reki2000:master Jun 23, 2020
@wx257osn2 wx257osn2 deleted the speedup-cxx-again branch June 23, 2020 04:02
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