https://github.com/johansenja/levenshtein_str
A Ruby gem for getting the levenshtein distance between 2 strings, written in Crystal.
https://github.com/johansenja/levenshtein_str
Last synced: 8 months ago
JSON representation
A Ruby gem for getting the levenshtein distance between 2 strings, written in Crystal.
- Host: GitHub
- URL: https://github.com/johansenja/levenshtein_str
- Owner: johansenja
- Created: 2020-05-08T16:57:33.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-08T20:33:42.000Z (over 5 years ago)
- Last Synced: 2025-02-11T19:48:15.165Z (8 months ago)
- Language: Ruby
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# String#levenshtein
[](https://badge.fury.io/rb/levenshtein_str)
A performant Ruby gem for getting the [levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) between 2 strings, with the leg work done in Crystal.
## Installation:
### System Requirements
- crystal
- MacOS (untested in Linux)```ruby
# Gemfile
gem "levenshtein_str"
```then
`bundle install`
## Usage:
```ruby
# app.rb
require 'levenshtein_str'puts "hello".levenshtein("world")
```then
`ruby app.rb # => 4`
## Benchmarks
A pure Ruby implementation vs this crystal gem. See `./benchmark` file for full details. Run them with
```
./benchmark
```
Note it takes a while to run the full set, especially the memory ones.### Iterations Per Second
- "" and "" Same-ish, often Ruby ~1.08x quicker (no type conversion overheads)
- "abd" and "abc" Crystal ~2x quicker
- "abcdefghi" and "0123456789" Crystal ~2.25x quicker
- [whole alphabet] vs "012345" Crystal ~2.37x quicker### Memory
- "" and "" Same
- "abd" and "abc" Ruby 25.2x more
- "abcdefghi" and "0123456789" Ruby 141.5x more
- [whole alphabet] vs "012345" Ruby 212x moreSee `./benchmark` file for full detailed results.
## Template
Based on [this](https://github.com/johansenja/crystal_gem_template) template for writing Ruby gems in Crystal.
## Contributions && Testing
Testing for now can just be done using Ruby:
`rspec`
Contributions are welcome.
## License
[MIT](https://rem.mit-license.org)