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!
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 objectnumber
: the number of executions you’d like to run the stmt.my_setup = "from mongoengine import *"
print(f"Cities: {timeit.timeit(stmt=Cities.objects(), setup=my_setup, number=10)}")
>Cities: 0.0002848450000003666