You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # xxhash
  2. [![Go Reference](https://pkg.go.dev/badge/github.com/cespare/xxhash/v2.svg)](https://pkg.go.dev/github.com/cespare/xxhash/v2)
  3. [![Test](https://github.com/cespare/xxhash/actions/workflows/test.yml/badge.svg)](https://github.com/cespare/xxhash/actions/workflows/test.yml)
  4. xxhash is a Go implementation of the 64-bit [xxHash] algorithm, XXH64. This is a
  5. high-quality hashing algorithm that is much faster than anything in the Go
  6. standard library.
  7. This package provides a straightforward API:
  8. ```
  9. func Sum64(b []byte) uint64
  10. func Sum64String(s string) uint64
  11. type Digest struct{ ... }
  12. func New() *Digest
  13. ```
  14. The `Digest` type implements hash.Hash64. Its key methods are:
  15. ```
  16. func (*Digest) Write([]byte) (int, error)
  17. func (*Digest) WriteString(string) (int, error)
  18. func (*Digest) Sum64() uint64
  19. ```
  20. The package is written with optimized pure Go and also contains even faster
  21. assembly implementations for amd64 and arm64. If desired, the `purego` build tag
  22. opts into using the Go code even on those architectures.
  23. [xxHash]: http://cyan4973.github.io/xxHash/
  24. ## Compatibility
  25. This package is in a module and the latest code is in version 2 of the module.
  26. You need a version of Go with at least "minimal module compatibility" to use
  27. github.com/cespare/xxhash/v2:
  28. * 1.9.7+ for Go 1.9
  29. * 1.10.3+ for Go 1.10
  30. * Go 1.11 or later
  31. I recommend using the latest release of Go.
  32. ## Benchmarks
  33. Here are some quick benchmarks comparing the pure-Go and assembly
  34. implementations of Sum64.
  35. | input size | purego | asm |
  36. | ---------- | --------- | --------- |
  37. | 4 B | 1.3 GB/s | 1.2 GB/s |
  38. | 16 B | 2.9 GB/s | 3.5 GB/s |
  39. | 100 B | 6.9 GB/s | 8.1 GB/s |
  40. | 4 KB | 11.7 GB/s | 16.7 GB/s |
  41. | 10 MB | 12.0 GB/s | 17.3 GB/s |
  42. These numbers were generated on Ubuntu 20.04 with an Intel Xeon Platinum 8252C
  43. CPU using the following commands under Go 1.19.2:
  44. ```
  45. benchstat <(go test -tags purego -benchtime 500ms -count 15 -bench 'Sum64$')
  46. benchstat <(go test -benchtime 500ms -count 15 -bench 'Sum64$')
  47. ```
  48. ## Projects using this package
  49. - [InfluxDB](https://github.com/influxdata/influxdb)
  50. - [Prometheus](https://github.com/prometheus/prometheus)
  51. - [VictoriaMetrics](https://github.com/VictoriaMetrics/VictoriaMetrics)
  52. - [FreeCache](https://github.com/coocood/freecache)
  53. - [FastCache](https://github.com/VictoriaMetrics/fastcache)