Skip to content

Commit

Permalink
Use min() builtin function, update Go minimum version to 1.21
Browse files Browse the repository at this point in the history
benchstat does not indicate any performance regression.

goos: linux
goarch: amd64
pkg: github.com/agnivade/levenshtein
cpu: AMD Ryzen 7 7840U w/ Radeon  780M Graphics
                       │ before.txt  │             after.txt              │
                       │   sec/op    │   sec/op     vs base               │
Simple/ASCII-16          134.3n ± 0%   134.5n ± 0%       ~ (p=0.135 n=20)
Simple/French-16         253.8n ± 0%   253.5n ± 0%       ~ (p=0.155 n=20)
Simple/Nordic-16         499.4n ± 0%   498.1n ± 0%  -0.26% (p=0.005 n=20)
Simple/long_string-16    1.853µ ± 0%   1.852µ ± 0%       ~ (p=0.878 n=20)
Simple/Tibetan-16        414.3n ± 0%   414.4n ± 0%       ~ (p=0.952 n=20)
All/ASCII/agniva-16      136.4n ± 0%   136.4n ± 0%       ~ (p=0.941 n=20)
All/ASCII/arbovm-16      193.0n ± 0%   192.6n ± 0%       ~ (p=0.151 n=20)
All/ASCII/dgryski-16     198.6n ± 0%   198.8n ± 1%       ~ (p=0.292 n=20)
All/French/agniva-16     255.9n ± 0%   255.9n ± 0%       ~ (p=0.899 n=20)
All/French/arbovm-16     332.1n ± 0%   331.6n ± 0%       ~ (p=0.857 n=20)
All/French/dgryski-16    333.2n ± 0%   333.1n ± 0%       ~ (p=0.732 n=20)
All/Nordic/agniva-16     500.1n ± 0%   499.9n ± 0%       ~ (p=0.673 n=20)
All/Nordic/arbovm-16     604.1n ± 0%   606.6n ± 0%  +0.41% (p=0.041 n=20)
All/Nordic/dgryski-16    612.4n ± 0%   612.4n ± 0%       ~ (p=0.984 n=20)
All/Tibetan/agniva-16    414.4n ± 0%   414.5n ± 0%       ~ (p=0.753 n=20)
All/Tibetan/arbovm-16    501.4n ± 1%   499.1n ± 1%       ~ (p=0.262 n=20)
All/Tibetan/dgryski-16   504.9n ± 0%   504.8n ± 0%       ~ (p=0.888 n=20)
geomean                  365.7n        365.6n       -0.03%
  • Loading branch information
psadac authored and agnivade committed Sep 24, 2024
1 parent 8c681eb commit 02603e0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/agnivade/levenshtein

go 1.13
go 1.21

require (
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0
Expand Down
9 changes: 1 addition & 8 deletions levenshtein.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func ComputeDistance(a, b string) int {
for j := 1; j <= lenS1; j++ {
current := x[j-1] // match
if s2[i-1] != s1[j-1] {
current = min(min(x[j-1]+1, prev+1), x[j]+1)
current = min(x[j-1]+1, prev+1, x[j]+1)
}
x[j-1] = prev
prev = current
Expand All @@ -80,10 +80,3 @@ func ComputeDistance(a, b string) int {
}
return int(x[lenS1])
}

func min(a, b uint16) uint16 {
if a < b {
return a
}
return b
}

0 comments on commit 02603e0

Please sign in to comment.