| commit | 570f3051b58d1999e46715451773187bc4d4bc8c | [log] [tgz] |
|---|---|---|
| author | Benedikt Lang <github@benediktlang.de> | Fri Dec 19 20:56:21 2014 |
| committer | Benedikt Lang <github@benediktlang.de> | Fri Dec 19 20:56:21 2014 |
| tree | 31d239ee9f99b3f3f8697b38c92e3cdd4bc16ee6 | |
| parent | 35e41ad4eed241155af9bc76e4e9c32625e8a49b [diff] |
String benchmark results
semver is a Semantic Versioning library written in golang. It fully covers spec version 2.0.0.
$ go get github.com/blang/semver
Note: Always vendor your dependencies or fix on a specific version tag.
import github.com/blang/semver
v1, err := semver.New("1.0.0-beta")
v2, err := semver.New("2.0.0-beta")
v1.Compare(v2)
Also check the GoDocs.
Have a look at full examples in examples/main.go
import github.com/blang/semver v, err := semver.New("0.0.1-alpha.preview+123.github") fmt.Printf("Major: %d\n", v.Major) fmt.Printf("Minor: %d\n", v.Minor) fmt.Printf("Patch: %d\n", v.Patch) fmt.Printf("Pre: %s\n", v.Pre) fmt.Printf("Build: %s\n", v.Build) // Prerelease versions array if len(v.Pre) > 0 { fmt.Println("Prerelease versions:") for i, pre := range v.Pre { fmt.Printf("%d: %q\n", i, pre) } } // Build meta data array if len(v.Build) > 0 { fmt.Println("Build meta data:") for i, build := range v.Build { fmt.Printf("%d: %q\n", i, build) } } v001, err := semver.New("0.0.1") // Compare using helpers: v.GT(v2), v.LT, v.GTE, v.LTE v001.GT(v) == true v.LT(v001) == true v.GTE(v) == true v.LTE(v) == true // Or use v.Compare(v2) for comparisons (-1, 0, 1): v001.Compare(v) == 1 v.Compare(v001) == -1 v.Compare(v) == 0 // Manipulate Version in place: v.Pre[0], err = semver.NewPRVersion("beta") if err != nil { fmt.Printf("Error parsing pre release version: %q", err) } fmt.Println("\nValidate versions:") v.Build[0] = "?" err = v.Validate() if err != nil { fmt.Printf("Validation failed: %s\n", err) }
BenchmarkParseSimple 5000000 328 ns/op 49 B/op 1 allocs/op BenchmarkParseComplex 1000000 2105 ns/op 263 B/op 7 allocs/op BenchmarkParseAverage 1000000 1301 ns/op 168 B/op 4 allocs/op BenchmarkStringSimple 10000000 214 ns/op 16 B/op 2 allocs/op BenchmarkStringComplex 3000000 583 ns/op 88 B/op 4 allocs/op BenchmarkStringAverage 3000000 461 ns/op 56 B/op 3 allocs/op BenchmarkValidateSimple 500000000 7.92 ns/op 0 B/op 0 allocs/op BenchmarkValidateComplex 2000000 923 ns/op 0 B/op 0 allocs/op BenchmarkValidateAverage 5000000 452 ns/op 0 B/op 0 allocs/op BenchmarkCompareSimple 100000000 11.2 ns/op 0 B/op 0 allocs/op BenchmarkCompareComplex 50000000 40.9 ns/op 0 B/op 0 allocs/op BenchmarkCompareAverage 50000000 43.8 ns/op 0 B/op 0 allocs/op BenchmarkSort 5000000 436 ns/op 259 B/op 2 allocs/op
See benchmark cases at semver_test.go
I simply couldn‘t find any lib supporting the full spec. Others were just wrong or used reflection and regex which i don’t like.
Feel free to make a pull request. For bigger changes create a issue first to discuss about it.
See LICENSE file.