Git Product home page Git Product logo

diskdict's Introduction

What Is This?

DiskDict is a replacement for Python dict object with one big difference. When the number of items in the dict is larger than cache_size, the disk will be used to store newly added data. This makes it possible for the dict to contain more data than the available RAM. The drawback is that the dict becomes much slower, but still usable.

The disk data is stored in a temp file, which is removed by the OS when process exists.

Usage Example

DiskDict could/should be used as a default dict object.

d = DiskDict(cache_size=2)
d[1] = 1
d[2] = 4
d[3] = 9
d[4] = 16
d[5] = 25

# d == {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

d[10] = 100
d[20] = 400
d[30] = 900
d[40] = 1600
d[50] = 2500

# d = {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 40: 1600, 10: 100, 50: 2500, 20: 400, 30: 900}

d[1] = -1
d[2] = -4
d[3] = -9
d[4] = -16
d[5] = -25

# d = {1: -1, 2: -4, 3: -9, 4: -16, 5: -25, 40: 1600, 10: 100, 50: 2500, 20: 400, 30: 900}

# d.counters = {'mem_hits': 6, 'misses': 0, 'cache_file_size': 63, 'set_ops': 15,
#               'get_ops': 25, 'mem_items': 1, 'disk_items': 8, 'disk_hits': 19,
#               'len': 9, 'del_ops': 1}

Speed Tests

SSD Laptop cache_size=0

Write   : n=1000000, s='a'*1024, ops/s=85607
Read SEQ: n=1000000, s='a'*1024, ops/s=131875
Read RND: n=1000000, s='a'*1024, ops/s=106608

Write   : n=1000000, s=range(100), ops/s=28614
Read SEQ: n=1000000, s=range(100), ops/s=27398
Read RND: n=1000000, s=range(100), ops/s=26072

SSD Laptop cache_size=1000000 (disk not used)

Write   : n=1000000, s='a'*1024, ops/s=316754
Read SEQ: n=1000000, s='a'*1024, ops/s=704680
Read RND: n=1000000, s='a'*1024, ops/s=409498

History

2014-11-04:

Added more dict-methods

2014-01-23:

First release.

diskdict's People

Contributors

ddofborg avatar

Watchers

James Cloos 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.