Home

Awesome

fastest-levenshtein :rocket:

Fastest JS/TS implemenation of Levenshtein distance.<br> Measure the difference between two strings.

Coverage Status npm

$ npm i fastest-levenshtein

Usage

Node

const {distance, closest} = require('fastest-levenshtein')

// Print levenshtein-distance between 'fast' and 'faster' 
console.log(distance('fast', 'faster'))
//=> 2

// Print string from array with lowest edit-distance to 'fast'
console.log(closest('fast', ['slow', 'faster', 'fastest']))
//=> 'faster'

Deno

import {distance, closest} from 'https://deno.land/x/fastest_levenshtein/mod.ts'

// Print levenshtein-distance between 'fast' and 'faster' 
console.log(distance('fast', 'faster'))
//=> 2

// Print string from array with lowest edit-distance to 'fast'
console.log(closest('fast', ['slow', 'faster', 'fastest']))
//=> 'faster'

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.

Test TargetN=4N=8N=16N=32N=64N=128N=256N=512N=1024
fastest-levenshtein44423237021076445951049291.586.6422.245.473
js-levenshtein2126110030293982422357.6214.773.7170.934
leven196886884160643611730.347.6041.9290.478
fast-levenshtein185776112126534589.4122.705.6761.4280.348
levenshtein-edit-distance229687445149340910928.077.0951.7890.445

Relative Performance

This image shows the relative performance between fastest-levenshtein and js-levenshtein (the 2nd fastest). fastest-levenshtein is always a lot faster. y-axis shows "times faster".

Benchmark

License

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