1# xxhash [![GoDoc](https://godoc.org/github.com/OneOfOne/xxhash?status.svg)](https://godoc.org/github.com/OneOfOne/xxhash) [![Build Status](https://travis-ci.org/OneOfOne/xxhash.svg?branch=master)](https://travis-ci.org/OneOfOne/xxhash) [![Coverage](https://gocover.io/_badge/github.com/OneOfOne/xxhash)](https://gocover.io/github.com/OneOfOne/xxhash) 2 3This is a native Go implementation of the excellent [xxhash](https://github.com/Cyan4973/xxHash)* algorithm, an extremely fast non-cryptographic Hash algorithm, working at speeds close to RAM limits. 4 5* The C implementation is ([Copyright](https://github.com/Cyan4973/xxHash/blob/master/LICENSE) (c) 2012-2014, Yann Collet) 6 7## Install 8 9 go get github.com/OneOfOne/xxhash 10 11## Features 12 13* On Go 1.7+ the pure go version is faster than CGO for all inputs. 14* Supports ChecksumString{32,64} xxhash{32,64}.WriteString, which uses no copies when it can, falls back to copy on appengine. 15* The native version falls back to a less optimized version on appengine due to the lack of unsafe. 16* Almost as fast as the mostly pure assembly version written by the brilliant [cespare](https://github.com/cespare/xxhash), while also supporting seeds. 17* To manually toggle the appengine version build with `-tags safe`. 18 19## Benchmark 20 21### Core i7-4790 @ 3.60GHz, Linux 4.12.6-1-ARCH (64bit), Go tip (+ff90f4af66 2017-08-19) 22 23```bash 24➤ go test -bench '64' -count 5 -tags cespare | benchstat /dev/stdin 25name time/op 26 27# https://github.com/cespare/xxhash 28XXSum64Cespare/Func-8 160ns ± 2% 29XXSum64Cespare/Struct-8 173ns ± 1% 30XXSum64ShortCespare/Func-8 6.78ns ± 1% 31XXSum64ShortCespare/Struct-8 19.6ns ± 2% 32 33# this package (default mode, using unsafe) 34XXSum64/Func-8 170ns ± 1% 35XXSum64/Struct-8 182ns ± 1% 36XXSum64Short/Func-8 13.5ns ± 3% 37XXSum64Short/Struct-8 20.4ns ± 0% 38 39# this package (appengine, *not* using unsafe) 40XXSum64/Func-8 241ns ± 5% 41XXSum64/Struct-8 243ns ± 6% 42XXSum64Short/Func-8 15.2ns ± 2% 43XXSum64Short/Struct-8 23.7ns ± 5% 44 45CRC64ISO-8 1.23µs ± 1% 46CRC64ISOString-8 2.71µs ± 4% 47CRC64ISOShort-8 22.2ns ± 3% 48 49Fnv64-8 2.34µs ± 1% 50Fnv64Short-8 74.7ns ± 8% 51# 52``` 53 54## Usage 55 56```go 57 h := xxhash.New64() 58 // r, err := os.Open("......") 59 // defer f.Close() 60 r := strings.NewReader(F) 61 io.Copy(h, r) 62 fmt.Println("xxhash.Backend:", xxhash.Backend) 63 fmt.Println("File checksum:", h.Sum64()) 64``` 65 66[<kbd>playground</kbd>](http://play.golang.org/p/rhRN3RdQyd) 67 68## TODO 69 70* Rewrite the 32bit version to be more optimized. 71* General cleanup as the Go inliner gets smarter. 72 73## License 74 75This project is released under the Apache v2. licence. See [LICENCE](LICENCE) for more details. 76