Skip to content

Commit

Permalink
Major optimization to the safe version of xxhash on Go 1.7 (tip)
Browse files Browse the repository at this point in the history
Based on https://docs.google.com/document/d/1vdAEAjYdzjnPA9WDOQ1e4e05cYVMpqSxJYZT33Cqw2g/edit

tested with https://docs.google.com/document/d/1vdAEAjYdzjnPA9WDOQ1e4e05cYVMpqSxJYZT33Cqw2g/edit#

	name                    old time/op    new time/op    delta
	XXChecksum32-8          1.35µs ±12%    0.67µs ± 3%  -50.49%          (p=0.008 n=5+5)
	XXChecksumString32-8    1.78µs ± 2%    1.21µs ± 1%  -32.06%          (p=0.008 n=5+5)
	XXChecksum64-8          1.14µs ± 5%    0.35µs ± 2%  -69.70%          (p=0.008 n=5+5)
	XXChecksumString64-8    1.68µs ± 1%    0.86µs ± 1%  -48.74%          (p=0.008 n=5+5)
  • Loading branch information
OneOfOne committed Mar 13, 2016
1 parent 10348e4 commit 623cd5f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions native/xxhash_safe.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ func newbyteReader(in []byte) byteReader {
}

func (br byteReader) Uint32(i int) uint32 {
return uint32(br[i]) | uint32(br[i+1])<<8 | uint32(br[i+2])<<16 | uint32(br[i+3])<<24
br = br[i : i+4]
return uint32(br[0]) | uint32(br[1])<<8 | uint32(br[2])<<16 | uint32(br[3])<<24
}

func (br byteReader) Uint64(i int) uint64 {
return uint64(br[i]) | uint64(br[i+1])<<8 | uint64(br[i+2])<<16 | uint64(br[i+3])<<24 |
uint64(br[i+4])<<32 | uint64(br[i+5])<<40 | uint64(br[i+6])<<48 | uint64(br[i+7])<<56
br = br[i : i+8]
return uint64(br[0]) | uint64(br[1])<<8 | uint64(br[2])<<16 | uint64(br[3])<<24 |
uint64(br[4])<<32 | uint64(br[5])<<40 | uint64(br[6])<<48 | uint64(br[7])<<56
}

func (br byteReader) Byte(i int) byte {
Expand Down

0 comments on commit 623cd5f

Please sign in to comment.