You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

4 years ago
  1. # js-levenshtein [![Build Status](https://travis-ci.org/gustf/js-levenshtein.svg?branch=master)](https://travis-ci.org/gustf/js-levenshtein)
  2. A very efficient JS implementation calculating the Levenshtein distance, i.e. the difference between two strings.
  3. Based on Wagner-Fischer dynamic programming algorithm, optimized for speed and memory
  4. - use a single distance vector instead of a matrix
  5. - loop unrolling on the outer loop
  6. - remove common prefixes/postfixes from the calculation
  7. - minimize the number of comparisons
  8. ## Install
  9. ```
  10. $ npm install --save js-levenshtein
  11. ```
  12. ## Usage
  13. ```js
  14. const levenshtein = require('js-levenshtein');
  15. levenshtein('kitten', 'sitting');
  16. //=> 3
  17. ```
  18. ## Benchmark
  19. ```
  20. $ npm run bench
  21. 50 paragraphs, length max=500 min=240 avr=372.5
  22. 162 op/s » js-levenshtein
  23. 98 op/s » talisman
  24. 94 op/s » levenshtein-edit-distance
  25. 85 op/s » leven
  26. 39 op/s » fast-levenshtein
  27. 100 sentences, length max=170 min=6 avr=57.5
  28. 3,076 op/s » js-levenshtein
  29. 2,024 op/s » talisman
  30. 1,817 op/s » levenshtein-edit-distance
  31. 1,633 op/s » leven
  32. 800 op/s » fast-levenshtein
  33. 2000 words, length max=20 min=3 avr=9.5
  34. 3,119 op/s » js-levenshtein
  35. 2,416 op/s » talisman
  36. 2,141 op/s » levenshtein-edit-distance
  37. 1,855 op/s » leven
  38. 1,260 op/s » fast-levenshtein
  39. ```
  40. Benchmarks was performed with node v8.12.0 on a MacBook Pro 15", 2.9 GHz Intel Core i9
  41. ## License
  42. MIT © Gustaf Andersson