fast-replace/go-fast-replace/README.md

54 lines
1.1 KiB
Markdown
Raw Normal View History

2023-12-30 21:35:09 +00:00
# Go Fast Replace
An implementation in Go.
## To build
2023-12-30 21:42:14 +00:00
````shell
2023-12-30 21:35:09 +00:00
make build
````
## To run
2023-12-30 21:42:14 +00:00
````shell
2023-12-30 21:35:09 +00:00
make run
````
## To test
2023-12-30 21:42:14 +00:00
````shell
2023-12-30 21:35:09 +00:00
make test
````
## Conclusions
### Replace
Current implementations:
- `bm` uses `strings.NewReplacer` which uses the [BoyerMoore](https://go.dev/src/strings/search.go) algorithm.
- `cw` uses [CommentzWalter](https://en.wikipedia.org/wiki/Commentz-Walter_algorithm) algorithm.
#### Results
- `bm` varies a lot, but is never over _460µs_.
- `cw` is a lot slower, at around _3.5ms_, but it can search for multiple patterns at once.
````shell
$ make run
./bin/corpus
Creating corpus...
./bin/pairs
Creating pairs...
./bin/replace
bm: 273.621µs
cw: 2.939254ms
````
#### Todo:
- Implement parallelism on the CommentzWalter implementation.
- [BoyerMoore variants](https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm#Variants)
- [RabinKarp](https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm) algorithm.
- [AhoCorasick](https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm) algorithm.