Giter Club home page Giter Club logo

slot-memory-test's Introduction

Python slots memory consumption test

Test memory consumption of normal (new style) classes vs. classes with slots in python.

$ ./run.sh
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/2.7/bin/python
New python executable in /Users/vkuznetsov/Documents/prog/tmp/test-slots/env/bin/python
Installing setuptools, pip, wheel...done.
Collecting memory-profiler
Collecting psutil
Installing collected packages: memory-profiler, psutil
Successfully installed memory-profiler-0.41 psutil-4.1.0

Running tests with python

Profiling with slots:
Filename: slots.py

Line #    Mem usage    Increment   Line Contents
================================================
    27      9.7 MiB      0.0 MiB   @profile
    28                             def test(cls):
    29     24.9 MiB     15.2 MiB       return [cls(n) for n in range(100000)]


Profiling without slots (normal classes with __dict__):
Filename: slots.py

Line #    Mem usage    Increment   Line Contents
================================================
    27      9.8 MiB      0.0 MiB   @profile
    28                             def test(cls):
    29     52.7 MiB     42.8 MiB       return [cls(n) for n in range(100000)]

The test above uses default python (python2 in my case) but it's also possible to specifically test on python3, pypy, or any other interpreter. For example:

$ ./run.sh python3

slot-memory-test's People

Contributors

kvas-it avatar

Stargazers

 avatar

Watchers

 avatar  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.