~ubuntu-branches/ubuntu/vivid/juju-core/vivid-updates

« back to all changes in this revision

Viewing changes to src/github.com/dustin/go-humanize/ftoa_test.go

  • Committer: Package Import Robot
  • Author(s): Curtis C. Hovey
  • Date: 2015-09-29 19:43:29 UTC
  • mfrom: (47.1.4 wily-proposed)
  • Revision ID: package-import@ubuntu.com-20150929194329-9y496tbic30hc7vp
Tags: 1.24.6-0ubuntu1~15.04.1
Backport of 1.24.6 from wily. (LP: #1500916, #1497087)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package humanize
 
2
 
 
3
import (
 
4
        "fmt"
 
5
        "regexp"
 
6
        "strconv"
 
7
        "testing"
 
8
)
 
9
 
 
10
func TestFtoa(t *testing.T) {
 
11
        testList{
 
12
                {"200", Ftoa(200), "200"},
 
13
                {"2", Ftoa(2), "2"},
 
14
                {"2.2", Ftoa(2.2), "2.2"},
 
15
                {"2.02", Ftoa(2.02), "2.02"},
 
16
                {"200.02", Ftoa(200.02), "200.02"},
 
17
        }.validate(t)
 
18
}
 
19
 
 
20
func BenchmarkFtoaRegexTrailing(b *testing.B) {
 
21
        trailingZerosRegex := regexp.MustCompile(`\.?0+$`)
 
22
 
 
23
        b.ResetTimer()
 
24
        for i := 0; i < b.N; i++ {
 
25
                trailingZerosRegex.ReplaceAllString("2.00000", "")
 
26
                trailingZerosRegex.ReplaceAllString("2.0000", "")
 
27
                trailingZerosRegex.ReplaceAllString("2.000", "")
 
28
                trailingZerosRegex.ReplaceAllString("2.00", "")
 
29
                trailingZerosRegex.ReplaceAllString("2.0", "")
 
30
                trailingZerosRegex.ReplaceAllString("2", "")
 
31
        }
 
32
}
 
33
 
 
34
func BenchmarkFtoaFunc(b *testing.B) {
 
35
        for i := 0; i < b.N; i++ {
 
36
                stripTrailingZeros("2.00000")
 
37
                stripTrailingZeros("2.0000")
 
38
                stripTrailingZeros("2.000")
 
39
                stripTrailingZeros("2.00")
 
40
                stripTrailingZeros("2.0")
 
41
                stripTrailingZeros("2")
 
42
        }
 
43
}
 
44
 
 
45
func BenchmarkFmtF(b *testing.B) {
 
46
        for i := 0; i < b.N; i++ {
 
47
                fmt.Sprintf("%f", 2.03584)
 
48
        }
 
49
}
 
50
 
 
51
func BenchmarkStrconvF(b *testing.B) {
 
52
        for i := 0; i < b.N; i++ {
 
53
                strconv.FormatFloat(2.03584, 'f', 6, 64)
 
54
        }
 
55
}