2025-05-26

BigListの一部を再帰なしにしたけど、C#最適化すごいな。

メモリー使用量以外は再帰ありのほうがいいわ。

速度的には再帰しより再帰ありのほうが圧倒的に速い。

ベンチマークは1000行×100文字

マシンCore i5 10400F、メモリー16GB。

再帰なし。ブランチ rewrite_nonrecursive、Commit 84b25c1

https://github.com/oonyanya/FooList/commit/84b25c172b2f8792ad2d1a645c0b25ff7bf8093d

benchmark start

Allocated GC Memory:61,240bytes

add time:1025 ms

Allocated GC Memory:199,685,064bytes

replace 1 time:7274 ms

Allocated GC Memory:199,698,944bytes

replace 2 time:9565 ms

Allocated GC Memory:345,442,528bytes

replace 3 time:7716 ms

Allocated GC Memory:345,442,552bytes

enumratotion time:1125 ms

Allocated GC Memory:345,442,672bytes

clear buffer

Allocated GC Memory:82,728bytes

add line time:384 ms

Allocated GC Memory:41,048,400bytes

update line time:99 ms

Allocated GC Memory:41,048,464bytes

clear buffer

Allocated GC Memory:82,984bytes

Finished.Hit Any Key

再帰あり

benchmark start

Allocated GC Memory:60,752bytes

add time:1055 ms

Allocated GC Memory:199,622,776bytes

replace 1 time:6032 ms

Allocated GC Memory:199,636,920bytes

replace 2 time:8309 ms

Allocated GC Memory:369,227,696bytes

replace 3 time:6220 ms

Allocated GC Memory:369,227,696bytes

enumratotion time:1158 ms

Allocated GC Memory:369,227,840bytes

clear buffer

Allocated GC Memory:82,728bytes

add line time:357 ms

Allocated GC Memory:40,996,432bytes

update line time:75 ms

Allocated GC Memory:40,999,688bytes

clear buffer

Allocated GC Memory:82,984bytes

Finished.Hit Any Key

できたら、RemoveRangeInPlaceとRebalaceも再帰なしにしたいけど、どう書いたらいいのかわから

  • ぐぐったら、末尾再帰はx64だと自動的にスタックを使用しない形してくれるらしい。 https://qiita.com/Tokeiya/items/ff2da14e2254b53278b7 qiitaの内容を読んだ限りだとBigListのInsertInPlace()とかは最適化...

  • 再帰ありならキャッシュ的にも分岐予測的にも有利なんだからあたりまえ すこしはCPUの気持ちになって書いたらいかがか?

記事への反応(ブックマークコメント)

ログイン ユーザー登録
ようこそ ゲスト さん