The optimized naive string-search algorithm.
rust
use naive_opt::string_search;
let haystack = "111 a 111b";
let needle = "a";
let r = string_search(haystack, needle);
assert_eq!(r, Some(4));
rust
use naive_opt::Search;
let haystack = "111 a 111b";
let needle = "a";
let r = haystack.search(needle);
assert_eq!(r, Some(4));
rust
use naive_opt::SearchIn;
let haystack = "111 a 111b";
let needle = "a";
let r = needle.search_in(haystack);
assert_eq!(r, Some(4));
| name
| bench:en
| bench:ja
| musl:en
| musl:ja
|
|:------------------------|------------:|------------:|------------:|------------:|
| stdstrstr | 316.470 uc | 286.210 uc | 319.380 uc | 278.270 uc |
| stdstringstring | 315.270 uc | 275.250 uc | 324.910 uc | 277.140 uc |
| funcstrstr | 41.756 uc | 41.674 uc | 45.828 uc | 55.954 uc |
| funcstringstring | 41.752 uc | 41.840 uc | 45.671 uc | 56.052 uc |
| traitstrstr | 41.750 uc | 41.695 uc | 45.823 uc | 55.774 uc |
| traitstringstring | 41.786 uc | 41.858 uc | 45.667 uc | 55.963 uc |
us
is micro seconds:en
is english haystack.:ja
is japanese haystack.musl
is x86_64-unknown-linux-musl