Skip to main content

Scalene: A high-resolution, low-overhead CPU and memory profiler for Python

Project description


scalene: a high-performance CPU and memory profiler for Python

by Emery Berger

About Scalene

Scalene is a high-performance CPU and memory profiler for Python that does a few things that other Python profilers do not and cannot do.

  1. Scalene is fast. It uses sampling instead of instrumentation or relying on Python's tracing facilities.
  2. Scalene is precise. Unlike most other Python profilers, Scalene performs CPU profiling at the line level, pointing to the specific lines of code that are responsible for the execution time in your program. This level of detail can be much more useful information than the function-level profiles returned by most profilers.
  3. Scalene profiles memory usage. In addition to tracking CPU usage, Scalene also points to the specific lines of code responsible for memory growth. It accomplishes this via an included specialized memory allocator.


Scalene is distributed as a pip package. You can install it as follows:

  % pip install scalene

NOTE: Currently, installing Scalene in this way does not install its memory profiling library, so you will only be able to use it to perform CPU profiling. To take advantage of its memory profiling capability, you will need to download this repository.


The following command will run Scalene to only perform line-level CPU profiling on a provided example program.

  % python -m scalene test/

To perform both line-level CPU and memory profiling, you first need to build the specialized memory allocator by running make:

  % make

Profiling on a Mac OS X system:

  % DYLD_INSERT_LIBRARIES=$PWD/libscalene.dylib PYTHONMALLOC=malloc python -m scalene test/

Profiling on a Linux system:

  % LD_PRELOAD=$PWD/ PYTHONMALLOC=malloc python -m scalene test/

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for scalene, version 0.5.1
Filename, size File type Python version Upload date Hashes
Filename, size scalene-0.5.1-py3-none-any.whl (9.8 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size scalene-0.5.1.tar.gz (5.5 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page