cespare/xxhash

GitHub: cespare/xxhash

Go 语言实现的 64 位 xxHash 算法库,提供远超标准库速度的高性能非加密哈希计算。

Stars: 2137 | Forks: 138

# xxhash [![Go 参考文档](https://pkg.go.dev/badge/github.com/cespare/xxhash/v2.svg)](https://pkg.go.dev/github.com/cespare/xxhash/v2) [![测试](https://github.com/cespare/xxhash/actions/workflows/test.yml/badge.svg)](https://github.com/cespare/xxhash/actions/workflows/test.yml) xxhash 是 64 位 [xxHash] 算法(XXH64)的 Go 实现。这是一种 高质量的哈希算法,比 Go 标准库中的任何实现都要快得多。 此包提供了一个简单的 API: ``` func Sum64(b []byte) uint64 func Sum64String(s string) uint64 type Digest struct{ ... } func New() *Digest ``` `Digest` 类型实现了 hash.Hash64。它的主要方法是: ``` func (*Digest) Write([]byte) (int, error) func (*Digest) WriteString(string) (int, error) func (*Digest) Sum64() uint64 ``` 该包使用优化的纯 Go 编写,并且还包含针对 amd64 和 arm64 的更快的 汇编实现。如果需要,可以使用 `purego` 构建 tag, 在这些架构上强制使用 Go 代码。 ## 兼容性 此包在一个 module 中,最新代码位于该 module 的版本 2 中。 你需要使用具备“最小 module 兼容性”的 Go 版本才能使用 github.com/cespare/xxhash/v2: * 1.9.7+ 适用于 Go 1.9 * 1.10.3+ 适用于 Go 1.10 * Go 1.11 或更高版本 我建议使用最新发布的 Go 版本。 ## 基准测试 以下是一些比较 Sum64 的纯 Go 和汇编 实现的快速基准测试。 | 输入大小 | purego | asm | | ---------- | --------- | --------- | | 4 B | 1.3 GB/s | 1.2 GB/s | | 16 B | 2.9 GB/s | 3.5 GB/s | | 100 B | 6.9 GB/s | 8.1 GB/s | | 4 KB | 11.7 GB/s | 16.7 GB/s | | 10 MB | 12.0 GB/s | 17.3 GB/s | 这些数据是在 Ubuntu 20.04 系统上,使用 Intel Xeon Platinum 8252C CPU,并在 Go 1.19.2 下通过以下命令生成的: ``` benchstat <(go test -tags purego -benchtime 500ms -count 15 -bench 'Sum64$') benchstat <(go test -benchtime 500ms -count 15 -bench 'Sum64$') ``` ## 使用此包的项目 - [InfluxDB](https://github.com/influxdata/influxdb) - [Prometheus](https://github.com/prometheus/prometheus) - [VictoriaMetrics](https://github.com/VictoriaMetrics/VictoriaMetrics) - [FreeCache](https://github.com/coocood/freecache) - [FastCache](https://github.com/VictoriaMetrics/fastcache) - [Ristretto](https://github.com/dgraph-io/ristretto) - [Badger](https://github.com/dgraph-io/badger)
标签:EVTX分析, 日志审计, 自动回退