Knuth Morris Pratt algorithm with C++ and Rust [Solved]

Probably Joe Duffy - Safe Native Code.

Truth is both Joe and @matklad are right :slight_smile:. Besides potentially killing loop optimizations, C# has the added issue of needing a memory load to get an array’s length - if that misses in cache, you stall badly. Rust is better in this regard because sliced have the length in the fat ptr, which will likely be kept in a register or at worst, spilled to a stack slot.

But I agree with @matklad - biggest issue will be missed optimizations in some cases, not too dissimilar to inlining failures; for them, it’s rare that it’s the actual call (frame setup/teardown) that’s costly, but rather missed further optimizations.

2 Likes