Created
May 29, 2012 00:54
-
-
Save taliesinb/2821947 to your computer and use it in GitHub Desktop.
Benchmarking SplitByte implementations from https://gist.github.com/2821937, the proper way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package split | |
import "testing" | |
var long []byte | |
const sz = 24 | |
const runs = 32 | |
func init() { | |
long = make([]byte, 1 << sz) | |
for i := uint(0); i < sz-1; i++ { | |
long[1 << i] = 'X' | |
} | |
BenchmarkSplit1(nil) // warm things up | |
BenchmarkSplit2(nil) | |
BenchmarkSplit3(nil) | |
} | |
func BenchmarkSplit1(*testing.B) { | |
var data [][]byte | |
for j := 0 ; j < runs ; j++ { | |
data = SplitByte1(long, 'X') | |
} | |
if len(data) != sz { panic("incorrect") } | |
} | |
func BenchmarkSplit2(*testing.B) { | |
var data [][]byte | |
for j := 0 ; j < runs ; j++ { | |
data = SplitByte2(long, 'X') | |
} | |
if len(data) != sz { panic("incorrect") } | |
} | |
func BenchmarkSplit3(*testing.B) { | |
var data [][]byte | |
for j := 0 ; j < runs ; j++ { | |
data = SplitByte3(long, 'X') | |
} | |
if len(data) != sz { panic("incorrect") } | |
} | |
func TestSplit1(*testing.T) { | |
data1 := SplitByte1(long, 'X') | |
data2 := SplitByte2(long, 'X') | |
if len(data1) != len(data2) { | |
panic("not the same length") | |
} | |
for t := range data1 { | |
if len(data1[t]) != len(data2[t]) { panic("disagree") } | |
print(len(data1[t]), " ") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment