This lesson is being piloted (Beta version)

Check and improve the performance of your code

Overview

Teaching: 0 min
Exercises: 0 min
Questions
  • How to assess the performance of Python codes?

Objectives

Timing your codes

import timeit
def my_function():
    y = 3.1415
    for x in range(100):
        y = y ** 0.7
    return y

print(timeit.timeit(my_function, number=100000))
14.254935225006193

Within jupyter notebooks

import time

def sleeping(arg):
    time.sleep(0.1)

%timeit list(map(sleeping, range(24)))

Cython

Python Performance tips

Key Points