Created
February 14, 2013 18:14
Revisions
-
alberts created this gist
Feb 14, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ package sse42 //#include <string.h> //#cgo linux CFLAGS: -O3 -msse4.2 import "C" import "unsafe" func Equal(b1, b2 []byte) bool { if len(b1) != len(b2) { return false } if len(b1) == 0 { return true } return C.strncmp((*C.char)(unsafe.Pointer(&b1[0])), (*C.char)(unsafe.Pointer(&b2[0])), C.size_t(len(b1))) == 0 } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ package sse42 import ( "bytes" "testing" ) const size = 1 << 20 func BenchmarkEqual(b *testing.B) { b1 := make([]byte, size) b2 := make([]byte, size) // this should make it panic?! b1[1] = 1 b.ResetTimer() for i := 0; i < b.N; i++ { if !Equal(b1, b2) { panic("failed") } } } func BenchmarkBytesEqual(b *testing.B) { b1 := make([]byte, size) b2 := make([]byte, size) b.ResetTimer() for i := 0; i < b.N; i++ { if !bytes.Equal(b1, b2) { panic("failed") } } } func BenchmarkStringEqual(b *testing.B) { s1 := string(make([]byte, size)) s2 := string(make([]byte, size)) b.ResetTimer() for i := 0; i < b.N; i++ { if s1 != s2 { panic("failed") } } }