GithubHelp home page GithubHelp logo

pombredanne / intdict-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pelotoncycle/intdict

0.0 1.0 0.0 24 KB

High performance integer->object mapping in python

License: Apache License 2.0

Python 17.42% C 82.58%

intdict-1's Introduction

intdict

intdict is a high performance integer -> PyObject data structure intended for mapping 64 bit integers such as what might be returned by hash or id to a Python object.

Installation

pip install intdict

Usage

>>> from intdict import intdict
>>> d = intdict()
>>> d[1] = 'one'
>>> d[2] = 'two'
>>> d[1]
'one'
>>> d[3]
KeyError

You may also preallocate intdict objects to a specific size for even better performance.

>>> d = intdict(10000)

Cavets

intdict stores all signed 64 bit integers except for the value of -1. This happens to also be exactly the range of the hash function on a 64 bit machine and a superset of the range of values id can return.

Benchmarks

If you can live within intdict's mild restrictions, here are the performance numbers you can enjoy. These timings were taken from an Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz running Ubuntu 15.04.

Storing 1,000,000 sequential numbers

Dict type Seconds Memory
dict 15.3 1,153Mb
int dict 1.3 773Mb
prealloced 0.3 773Mb

Storing 1,000,000 random numbers

Dict type Seconds Memory
dict 3 1,234Mb
intdict 1.5 854Mb
prealloced 1.3 854Mb

intdict-1's People

Contributors

adamdeprince avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.