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 | 445.100 uc | 351.770 uc | 453.920 uc | 374.950 uc |
| stdstringstring | 438.650 uc | 353.290 uc | 456.160 uc | 376.580 uc |
| funcstrstr | 57.182 uc | 56.293 uc | 59.289 uc | 59.012 uc |
| funcstringstring | 56.079 uc | 56.269 uc | 58.694 uc | 58.678 uc |
| traitstrstr | 50.418 uc | 49.367 uc | 52.200 uc | 52.112 uc |
| traitstringstring | 49.448 uc | 49.501 uc | 52.080 uc | 52.057 uc |
| stdindices | 338.080 uc | 260.590 uc | 357.770 uc | 266.960 uc |
| funcindices | 55.877 uc | 55.891 uc | 58.164 uc | 58.097 uc |
| trait_indices | 51.534 uc | 51.547 uc | 54.863 uc | 54.808 uc |
us
is micro seconds:en
is english haystack.:ja
is japanese haystack.musl
is x86_64-unknown-linux-musl