Newton's Programmatic Measurements

npm

Need private packages and team management tools?Check out npm Orgs. »

node-levenshtein

2.0.13 • Public • Published

node-levenshtein 🚀

Fastest implementation of the Levenshtein distance algorithm - (up to 8x+ faster than closest competitor). This algorithm can be used to measure the similarity of two strings. The performance has been achieved by using a highly-optimized N-API module written in C++. Furthermore, this module has the fastest javascript implementation that runs for short strings (when N-API overhead is too big).

Note: if you need to take the edit distance of one string against many strings (maybe billions), I have created a GPU-implementation that will be atleast 1000x faster than this. Contact me, if you're interested.

This package requires node v8.6.0 or higher.

Build Status

Installation

$ npm install node-levenshtein --save

Usage

const levenshtein = require('node-levenshtein')
 
console.log(levenshtein('lorem', 'ipsum'))
//=> 4
 

Benchmark

I generated 500 pairs of strings with length N. I measured the ops/sec each library achieves to process all the given pairs. Higher is better. node-levenshtein is a lot faster in all cases.

Test Target N=4 N=8 N=16 N=32 N=64 N=128 N=256 N=512 N=1024
node-levenshtein 42423 17237 5577 3428 2013 596.1 182.6 49.88 12.99
js-levenshtein 24012 12684 4100 1311 371 97.25 25.40 6.404 1.632
leven 30291 11002 3378 907 227 59.94 15.59 3.958 0.998
talisman 29859 9782 3319 926 234 63.76 16.12 3.989 0.986
fast-levenshtein 23517 7686 2291 576 154 40.13 10.16 2.558 0.643
levenshtein-edit-distance 31423 10783 3209 851 214 56.13 14.24 3.694 0.931

Relative Performance

This image shows the relative performance between node-levenshtein and js-levenshtein (the 2nd fastest). As you can see, node-levenshtein is a lot faster for small strings, but especially for long strings (8x faster when N = 1024).

Benchmark

License

This project is licensed under the MIT License - see the LICENSE.md file for details

install

npm i node-levenshtein

Downloadsweekly downloads

12

version

2.0.13

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability