Package wildcard
provides utils for working with a classic wildcard matching (only ?
and *
are supported).
Match
function is a golang's adaptation of Java's O(1) space solution and ~ 3.37 times faster (76.0ns/22.5ns) then standard filepath.Match
.
package main
import (
"fmt"
"github.com/iamolegga/wildcard"
)
func main() {
fmt.Println(wildcard.Match("value", "v?l*"))
fmt.Println(wildcard.IsPattern("v?l*"))
}
It was compared with filepath.Match
function with several runs:
$ for i in {1..10}; do go test -run=NONE -bench=. ./... >> old.txt; done
$ # change implementation to `filepath.Match`
$ for i in {1..10}; do go test -run=NONE -bench=. ./... >> new.txt; done
$
$ benchstat old.txt new.txt
name old time/op new time/op delta
Match-4 22.5ns ± 2% 76.0ns ±19% +238.01% (p=0.000 n=10+10)
old
- current implementation
new
- utilize filepath.Match