Browse Source

Added benchmark for uint to byte or byte to uint.

tags/0.1.3
mikespook 13 years ago
parent
commit
6290a8ace6
1 changed files with 47 additions and 0 deletions
  1. +47
    -0
      src/pkg/gearman/gearman_test.go

+ 47
- 0
src/pkg/gearman/gearman_test.go View File

@@ -0,0 +1,47 @@
package gearman

import (
"testing"
)

func TestByteToUint32(t * testing.T) {
if u := byteToUint32([4]byte{0, 0, 0, 0}); u != 0 {
t.Errorf("Number %t should be zero.", u)
}
if u := byteToUint32([4]byte{0xF, 0xF, 0xF, 0xF}); u != 252645135 {
t.Errorf("Number %t should be 252645135.", u)
}
}

func BenchmarkByteToUnit32(b * testing.B) {
for i := 0; i < b.N; i++ {
byteToUint32([4]byte{0xF, 0xF, 0xF, 0xF});
}
}

func TestUint32ToByte(t * testing.T) {
if b := uint32ToByte(0); len(b) != 4 {
t.Errorf("%t", b)
} else {
for i := 0; i < 4; i ++ {
if b[i] != 0 {
t.Errorf("%t", b[i])
}
}
}
if b := uint32ToByte(252645135); len(b) != 4 {
t.Errorf("%t", b)
} else {
for i := 0; i < 4; i++ {
if b[i] != 0xf {
t.Errorf("%t", b[i])
}
}
}
}

func BenchmarkUint32ToByte(b *testing.B) {
for i := 0; i < b.N; i++ {
uint32ToByte(123456);
}
}

Loading…
Cancel
Save