Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is diffrence between number and repeat in python timeit?

Tags:

python

timeit

I can not understand the difference between number and repeat in timeit library, so would you kindly tell me what is the difference between them?

like image 821
mark080 Avatar asked Jun 25 '19 23:06

mark080


1 Answers

repeat specifies the number of samples to take.

number specifies the number of times to repeat the code for each sample.

Internally there is a loop like this:

samples = []
for _ in range(repeat):
    # start timer
    for _ in range(number):
        do_work()
    # end timer
    samples.append(duration)
like image 174
Dan D. Avatar answered Oct 28 '22 23:10

Dan D.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!