~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/hash/fnv/fnv_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
        "testing"
12
12
)
13
13
 
14
 
const testDataSize = 40
15
 
 
16
14
type golden struct {
17
15
        sum  []byte
18
16
        text string
134
132
        }
135
133
}
136
134
 
137
 
func Benchmark32(b *testing.B) {
138
 
        benchmark(b, New32())
139
 
}
140
 
 
141
 
func Benchmark32a(b *testing.B) {
142
 
        benchmark(b, New32a())
143
 
}
144
 
 
145
 
func Benchmark64(b *testing.B) {
146
 
        benchmark(b, New64())
147
 
}
148
 
 
149
 
func Benchmark64a(b *testing.B) {
150
 
        benchmark(b, New64a())
151
 
}
152
 
 
153
 
func benchmark(b *testing.B, h hash.Hash) {
 
135
func BenchmarkFnv32KB(b *testing.B) {
 
136
        benchmarkKB(b, New32())
 
137
}
 
138
 
 
139
func BenchmarkFnv32aKB(b *testing.B) {
 
140
        benchmarkKB(b, New32a())
 
141
}
 
142
 
 
143
func BenchmarkFnv64KB(b *testing.B) {
 
144
        benchmarkKB(b, New64())
 
145
}
 
146
 
 
147
func BenchmarkFnv64aKB(b *testing.B) {
 
148
        benchmarkKB(b, New64a())
 
149
}
 
150
 
 
151
func benchmarkKB(b *testing.B, h hash.Hash) {
 
152
        b.SetBytes(1024)
 
153
        data := make([]byte, 1024)
 
154
        for i := range data {
 
155
                data[i] = byte(i)
 
156
        }
 
157
        in := make([]byte, 0, h.Size())
 
158
 
154
159
        b.ResetTimer()
155
 
        b.SetBytes(testDataSize)
156
 
        data := make([]byte, testDataSize)
157
 
        for i := range data {
158
 
                data[i] = byte(i + 'a')
159
 
        }
160
 
 
161
 
        b.StartTimer()
162
 
        for todo := b.N; todo != 0; todo-- {
 
160
        for i := 0; i < b.N; i++ {
163
161
                h.Reset()
164
162
                h.Write(data)
165
 
                h.Sum(nil)
 
163
                h.Sum(in)
166
164
        }
167
165
}