fnv-c


Namefnv-c JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/botify-labs/fnv-c
SummaryPython 3.7+ FNV (fnv0, fnv1, fnv1a) non-cryptographic hash library implemented in C through libffi
upload_time2023-06-05 09:39:10
maintainer
docs_urlNone
authorFabien MARTY
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # fnv-c

[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/botify-labs/fnv-c/lint.yaml)](https://github.com/botify-labs/fnv-c/actions/workflows/lint.yaml)
[![Codecov](https://img.shields.io/codecov/c/github/botify-labs/fnv-c)](https://app.codecov.io/github/botify-labs/fnv-c)
[![pypi badge](https://img.shields.io/pypi/v/fnv-c?color=brightgreen)](https://pypi.org/project/fnv-c/)

## What is it?

**fnv-c** is a Python 3.7+ FNV (`fnv0`, `fnv1`, `fnv1a`) **non-cryptographic** hash library implemented in C through libffi.

FNV ("Fowler–Noll–Vo") is is a non-cryptographic hash function created by Glenn Fowler, Landon Curt Noll, and Kiem-Phong.
FNV is probably no the "best" non-cryptographic hash function but:

- it has a reasonably good distribution
- it's very fast
- it's very easy to implement *(even in some exotic stored procedures for example)* so you can use it everywhere

More details on [this Wikepedia article](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function).

## Features

- speed: 
    - up to **800 MB/s** hashing speed *(on Macbook Pro M1 (2020) with `fnv0_64`)*
    - **6 800%** faster than basic Python implementation, **70%** faster than `pyhash` *(when hashing 100 bytes with `fnv0_64` on a cloud VM)*
- portability:
    - tested with recent Python versions (3.7+)
    - compatible with ARM64
    - compatible (and tested) with PyPy

## Non features

- other hash algorithms *(this library is only about FNV algorithm)*
- too agressive CPU optimizations *(we prefer maximizing binary portability)*

## Benchmark

You have a benchmark script [here](bench.py) to bench `fnv-c` by yourself and to compare it with:
- [`fnvhash`](https://github.com/znerol/py-fnvhash) (pure python implementation)
- [`pyhash`](https://github.com/flier/pyfasthash) (more general hashing library with C++ extension)

### Comparisons with other libraries (`fnv0_64` on a cloud VM)

Differences with `fnvhash` are huge (from **35%** for one byte hashing to **19 000%** for 1 000 bytes hashing with `fnv0_64`)

Differences with `pyhash` (on `fnv0_64`) are shown with the following diagram:

![](bench.png)

### Influence of string size on `fnv-c` hashing speed (on a Macbook Pro M1 (2020) with `fnv0_64`)

![](bench2.png)

## How to install/use it?

```
pip install fnv-c
```

```python
import fnv_c

print(fnv_c.fnv0_32(b"foo bar"))
print(fnv_c.fnv0_64(b"foo bar"))
print(fnv_c.fnv1_32(b"foo bar"))
print(fnv_c.fnv1_64(b"foo bar"))
print(fnv_c.fnv1a_32(b"foo bar"))
print(fnv_c.fnv1a_64(b"foo bar"))
```

## Function signatures / API

Full API doc is available at: [https://botify-labs.github.io/fnv-c/fnv_c/](https://botify-labs.github.io/fnv-c/fnv_c/)

## Dev

See [this specific document](DEV.md)
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/botify-labs/fnv-c",
    "name": "fnv-c",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Fabien MARTY",
    "author_email": "fabien.marty@botify.com",
    "download_url": "https://files.pythonhosted.org/packages/42/ff/e861f1eeff2995b5971590729720f512837635a0b0b49924ac8ed1577dd4/fnv-c-0.2.0.tar.gz",
    "platform": null,
    "description": "# fnv-c\n\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/botify-labs/fnv-c/lint.yaml)](https://github.com/botify-labs/fnv-c/actions/workflows/lint.yaml)\n[![Codecov](https://img.shields.io/codecov/c/github/botify-labs/fnv-c)](https://app.codecov.io/github/botify-labs/fnv-c)\n[![pypi badge](https://img.shields.io/pypi/v/fnv-c?color=brightgreen)](https://pypi.org/project/fnv-c/)\n\n## What is it?\n\n**fnv-c** is a Python 3.7+ FNV (`fnv0`, `fnv1`, `fnv1a`) **non-cryptographic** hash library implemented in C through libffi.\n\nFNV (\"Fowler\u2013Noll\u2013Vo\") is is a non-cryptographic hash function created by Glenn Fowler, Landon Curt Noll, and Kiem-Phong.\nFNV is probably no the \"best\" non-cryptographic hash function but:\n\n- it has a reasonably good distribution\n- it's very fast\n- it's very easy to implement *(even in some exotic stored procedures for example)* so you can use it everywhere\n\nMore details on [this Wikepedia article](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function).\n\n## Features\n\n- speed: \n    - up to **800 MB/s** hashing speed *(on Macbook Pro M1 (2020) with `fnv0_64`)*\n    - **6 800%** faster than basic Python implementation, **70%** faster than `pyhash` *(when hashing 100 bytes with `fnv0_64` on a cloud VM)*\n- portability:\n    - tested with recent Python versions (3.7+)\n    - compatible with ARM64\n    - compatible (and tested) with PyPy\n\n## Non features\n\n- other hash algorithms *(this library is only about FNV algorithm)*\n- too agressive CPU optimizations *(we prefer maximizing binary portability)*\n\n## Benchmark\n\nYou have a benchmark script [here](bench.py) to bench `fnv-c` by yourself and to compare it with:\n- [`fnvhash`](https://github.com/znerol/py-fnvhash) (pure python implementation)\n- [`pyhash`](https://github.com/flier/pyfasthash) (more general hashing library with C++ extension)\n\n### Comparisons with other libraries (`fnv0_64` on a cloud VM)\n\nDifferences with `fnvhash` are huge (from **35%** for one byte hashing to **19 000%** for 1 000 bytes hashing with `fnv0_64`)\n\nDifferences with `pyhash` (on `fnv0_64`) are shown with the following diagram:\n\n![](bench.png)\n\n### Influence of string size on `fnv-c` hashing speed (on a Macbook Pro M1 (2020) with `fnv0_64`)\n\n![](bench2.png)\n\n## How to install/use it?\n\n```\npip install fnv-c\n```\n\n```python\nimport fnv_c\n\nprint(fnv_c.fnv0_32(b\"foo bar\"))\nprint(fnv_c.fnv0_64(b\"foo bar\"))\nprint(fnv_c.fnv1_32(b\"foo bar\"))\nprint(fnv_c.fnv1_64(b\"foo bar\"))\nprint(fnv_c.fnv1a_32(b\"foo bar\"))\nprint(fnv_c.fnv1a_64(b\"foo bar\"))\n```\n\n## Function signatures / API\n\nFull API doc is available at: [https://botify-labs.github.io/fnv-c/fnv_c/](https://botify-labs.github.io/fnv-c/fnv_c/)\n\n## Dev\n\nSee [this specific document](DEV.md)",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python 3.7+ FNV (fnv0, fnv1, fnv1a) non-cryptographic hash library implemented in C through libffi",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/botify-labs/fnv-c"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "42ffe861f1eeff2995b5971590729720f512837635a0b0b49924ac8ed1577dd4",
                "md5": "0f3e2ef1d61201998b7692fae99b5faa",
                "sha256": "66089a90921048a1b8ba35a5ab14aa79ad893984ffabacaa94e5813bdfe95cd2"
            },
            "downloads": -1,
            "filename": "fnv-c-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0f3e2ef1d61201998b7692fae99b5faa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3767,
            "upload_time": "2023-06-05T09:39:10",
            "upload_time_iso_8601": "2023-06-05T09:39:10.641677Z",
            "url": "https://files.pythonhosted.org/packages/42/ff/e861f1eeff2995b5971590729720f512837635a0b0b49924ac8ed1577dd4/fnv-c-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-05 09:39:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "botify-labs",
    "github_project": "fnv-c",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "fnv-c"
}
        
Elapsed time: 0.07623s