(Python) timeit module

Kepler·2020년 4월 9일
0

Python

목록 보기
11/12

Why timeit?

timeit runs your snippet of code millions of time (default value is 1000000) so that you get the statistically most relevant measurement of code execution time!

Syntax:

timeit.timeit(stmt, setup, timer, number)

  • stmt: the statement you want to measure; it defaults to ‘pass’.
  • setup: the code that you run before running the stmt; use this to import the required modules for our code.
  • timer: timeit.Timer object
  • number: the number of executions you’d like to run the stmt.

Usage:

my_setup = "from mongoengine import *"

print(f"Cities: {timeit.timeit(stmt=Cities.objects(), setup=my_setup, number=10)}")

>Cities: 0.0002848450000003666

참고: https://www.geeksforgeeks.org/timeit-python-examples/

profile
🔰

0개의 댓글