Browse Source

Start with a slice large enough for the minimum version

Closes #12
Chris Bandy 11 years ago
committed by Benedikt Lang
parent
commit
0575a3cfd7
2 changed files with 11 additions and 1 deletions
  1. +1
    -1
      semver.go
  2. +10
    -0
      semver_test.go

+ 1
- 1
semver.go View File

@ -30,7 +30,7 @@ type Version struct {
// Version to string // Version to string
func (v Version) String() string { func (v Version) String() string {
b := make([]byte, 0)
b := make([]byte, 0, 5)
b = strconv.AppendUint(b, v.Major, 10) b = strconv.AppendUint(b, v.Major, 10)
b = append(b, '.') b = append(b, '.')
b = strconv.AppendUint(b, v.Minor, 10) b = strconv.AppendUint(b, v.Minor, 10)


+ 10
- 0
semver_test.go View File

@ -301,6 +301,16 @@ func BenchmarkStringSimple(b *testing.B) {
} }
} }
func BenchmarkStringLarger(b *testing.B) {
const VERSION = "11.15.2012"
v, _ := New(VERSION)
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
v.String()
}
}
func BenchmarkStringComplex(b *testing.B) { func BenchmarkStringComplex(b *testing.B) {
const VERSION = "0.0.1-alpha.preview+123.456" const VERSION = "0.0.1-alpha.preview+123.456"
v, _ := New(VERSION) v, _ := New(VERSION)


Loading…
Cancel
Save