luaxxhash: a luajit implementation of xxhash

Date
Links

luaxxhash

A is a 32-bit LuaJIT implementation of xxhash. It requires no bindings or C libraries. It computes the hash of an entire string at a time rather than using a digest function. This implementation was designed to work in environments where loading a C library is difficult (e.g. some game engines) but still need a fast, non-cryptographic hash. I created this project to learn the LuaJIT FFI types and to test profiling options. Furthermore, it’s written in pure LuaJIT so it may be embedded in cross platform applications where it may be difficult to distribute binaries (for security reasons or otherwise).

Installation

git clone https://github.com/szensk/luaxxhash.git

Usage

local xxh32 = require("luaxxhash")
local str = "Cats are interesting."
assert(xxh32(str) == 0x65ED1AFC)

Benchmark

A comparison of selected hash functions on an Intel T6400 at 2.0GHz.

lua-xxhash: 54957.13/s 3959.19MB/s (C binding)
luaxxhash:  12435.24/s 895.854MB/s (pure LuaJIT)
pmurmur3:    5603.67/s 403.697MB/s (pure LuaJIT)