I’m playing with Rust to optimize bits of
Racket code that are too slow and in particular, I’m dealing with multiple search/replace operations on text. The performance of Racket being very low on this particular operation, I have written a simple FFI wrapper to perform the search/replace operation using Rust.
And indeed, it is much faster, dropping from around 140ms to 11ms using Rust (on a MB Pro 2.5Ggz i7). However I remain curious: The code performs 161 search/replace on a rather short text fragment (110KB) and I’m suprised it is that slow (I was naively expecting something like lower 1ms). I have also written a version using Clojure and Apache Common-lang
StringUtils.replaceEachRepeatedly, but so far It either indicates I’m very very bad at doing Clojure, or that is is much slower (500ms per iteration).
I have uploaded everything needed to test the code on GitHub ( https://github.com/octplane/replace-rust-benchmark ) and would appreciate some feedback from the community on:
- my naivety around code speed (and probably the fact the Replacing text is much more difficult to do than I thought)
- the possibility of optimising the code even more.
- anything enlightening about this.
Thank you for this,