Rustの大文字小文字を無視したソート:ベンチマークが示す意外な結果
Matching Puzzle Pieces and Disappointing Benchmarks
Rustで文字列を大文字小文字を無視してソートする方法を比較したベンチマーク記事。著者は、`to_lowercase()`を各要素に適用してからソートする従来の方法(`sort_by_cached_key`)と、比較時にイテレータで小文字変換を挟む方法(`sort_by`)、そして`unicase`クレートを使う方法を、様々な要素数で計測。結果は、要素数が1以外では`sort_by_cached_key`が最速で、イテレータ方式は予想以上に遅いことが判明。さらに、`unicase`は複雑な比較にもかかわらず高速な場合が多いという驚きの結果も示された。
The real surprise is that Unicase can often be faster, despite making the comparison more complex.