Merge branch 'master' into benchmark
This commit is contained in:
@@ -31,7 +31,7 @@ func main() {
|
||||
}
|
||||
|
||||
now := time.Now().Format(time.DateOnly)
|
||||
resultFile := path.Join(".", "results", head+"_"+now+".txt")
|
||||
resultFile := path.Join(".", "results", now+"_"+head+".txt")
|
||||
log.Printf("Writing results to %s", resultFile)
|
||||
outFile, err := os.Create(resultFile)
|
||||
if err != nil {
|
||||
|
@@ -450,3 +450,43 @@ func TestSizeReturns16(t *testing.T) {
|
||||
t.Errorf("Expected size to be 16, got %d", p.Size())
|
||||
}
|
||||
}
|
||||
|
||||
// region benchmarks
|
||||
|
||||
// With buffer pool
|
||||
func BenchmarkEncode(b *testing.B) {
|
||||
p := &PDU_HEADER{
|
||||
command_length: 16,
|
||||
command_id: 1,
|
||||
command_status: 0,
|
||||
sequence_number: 12345,
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
p.Encode()
|
||||
}
|
||||
}
|
||||
|
||||
// Without buffer pool
|
||||
func BenchmarkEncodeInto(b *testing.B) {
|
||||
p := &PDU_HEADER{
|
||||
command_length: 16,
|
||||
command_id: 1,
|
||||
command_status: 0,
|
||||
sequence_number: 12345,
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
buf := make([]uint8, 16)
|
||||
p.EncodeInto(&buf)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDecode(b *testing.B) {
|
||||
p := &PDU_HEADER{}
|
||||
data := []uint8{0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
p.Decode(data)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user