Пример #1
0
func becnchmark(b *testing.B, h hash.Hash32, n int64) {
	b.SetBytes(n)
	data := make([]byte, n)
	for i := range data {
		data[i] = byte(i)
	}
	in := make([]byte, 0, h.Size())
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		h.Reset()
		h.Write(data)
		h.Sum(in)
	}
}
Пример #2
0
func benchmark(b *testing.B, h hash.Hash32, n, alignment int64) {
	b.SetBytes(n)
	data := make([]byte, n+alignment)
	data = data[alignment:]
	for i := range data {
		data[i] = byte(i)
	}
	in := make([]byte, 0, h.Size())

	// Warm up
	h.Reset()
	h.Write(data)
	h.Sum(in)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		h.Reset()
		h.Write(data)
		h.Sum(in)
	}
}
Пример #3
0
	Describe("Reset", func() {

		It("sets back to 0", func() {
			Expect(jhash.Sum32()).To(Equal(uint32(0)))
			jhash.Write(key)
			Expect(jhash.Sum32()).NotTo(Equal(uint32(0)))
			jhash.Reset()
			Expect(jhash.Sum32()).To(Equal(uint32(0)))
		})

	})

	Describe("Size", func() {

		It("is 4", func() {
			Expect(jhash.Size()).To(Equal(4))
		})

	})

	Describe("BlockSize", func() {

		It("is 1", func() {
			Expect(jhash.BlockSize()).To(Equal(1))
		})

	})

	Describe("Sum32", func() {

		It("defaults to 0", func() {