github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/util/util_test.go (about) 1 package util 2 3 import ( 4 "bytes" 5 "testing" 6 ) 7 8 func TestXOR(t *testing.T) { 9 cases := [][3][]byte{ 10 { 11 {0xFF, 0xFF, 0xFF}, 12 {0xFF, 0xFF, 0xFF}, 13 {0x00, 0x00, 0x00}, 14 }, 15 { 16 {0x00, 0xFF, 0x00}, 17 {0xFF, 0xFF, 0xFF}, 18 {0xFF, 0x00, 0xFF}, 19 }, 20 { 21 {0x55, 0x55, 0x55}, 22 {0x55, 0xFF, 0xAA}, 23 {0x00, 0xAA, 0xFF}, 24 }, 25 } 26 27 for _, c := range cases { 28 r := XOR(c[0], c[1]) 29 if !bytes.Equal(r, c[2]) { 30 t.Error("XOR failed") 31 } 32 } 33 } 34 35 func BenchmarkHash256K(b *testing.B) { 36 buf := make([]byte, 256*1024) 37 NewTimeSeededRand().Read(buf) 38 b.SetBytes(int64(256 * 1024)) 39 b.ResetTimer() 40 for i := 0; i < b.N; i++ { 41 Hash(buf) 42 } 43 } 44 45 func BenchmarkHash512K(b *testing.B) { 46 buf := make([]byte, 512*1024) 47 NewTimeSeededRand().Read(buf) 48 b.SetBytes(int64(512 * 1024)) 49 b.ResetTimer() 50 for i := 0; i < b.N; i++ { 51 Hash(buf) 52 } 53 } 54 55 func BenchmarkHash1M(b *testing.B) { 56 buf := make([]byte, 1024*1024) 57 NewTimeSeededRand().Read(buf) 58 b.SetBytes(int64(1024 * 1024)) 59 b.ResetTimer() 60 for i := 0; i < b.N; i++ { 61 Hash(buf) 62 } 63 }