Code Monkey home page Code Monkey logo

memory_profiler's Introduction

Memory Profiler

This is a python module for monitoring memory consumption of a process as well as line-by-line analysis of memory consumption for python programs.

Installation

To install through easy_install or pip:

$ easy_install -U memory_profiler # pip install -U memory_profiler

To install from source, download the package, extract and type:

$ python setup.py install

Usage

The line-by-line profiler is used much in the same way of the line_profiler: you must first decorate the function you would like to profile with @profile:

@profile
def my_func():
    a = np.zeros((100, 100))
    b = np.zeros((1000, 1000))
    c = np.zeros((10000, 1000))
    return a, b, c

then execute the code passing the option "-m memory_profiler" to the python interpreter to load the memory_profiler module and "-l -v" to do a line-by-line analysis and print the result. If the file name was example.py, this would result in:

$ python -m memory_profiler -l -v example.py

Output will follow:

Line #    Mem usage   Line Contents
===================================
     3                @profile
     4     14.19 MB   def my_func():
     5     14.27 MB       a = np.zeros((100, 100))
     6     21.91 MB       b = np.zeros((1000, 1000))
     7     98.20 MB       c = np.zeros((10000, 1000))
     8     98.20 MB       return a, b, c

Bugs & wishlist

Maybe also print the increment in memory consumption.

Development

Latest sources are available from github:

https://github.com/fabianp/memory_profiler

Author: Fabian Pedregosa <[email protected]> License: Simplified BSD

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.