Calculate run time of a given function python
<p>I have created a function that takes in a another function as parameter and calculates the run time of that particular function. but when i run it, i can not seem to understand why this is not working . Does any one know why ? </p>

<pre><code>import time
import random
import timeit
import functools

def ListGenerator(rangeStart,rangeEnd,lenth):
 sampleList = random.sample(range(rangeStart,rangeEnd),lenth)
 return sampleList


def timeit(func):
    @functools.wraps(func)
    def newfunc(*args):
        startTime = time.time()
        func(*args)
        elapsedTime = time.time() - startTime
        print('function [{}] finished in {} ms'.format(
            func.__name__, int(elapsedTime * 1000)))
    return newfunc

@timeit
def bubbleSort(NumList):
    compCount,copyCount= 0,0

    for currentRange in range(len(NumList)-1,0,-1):
        for i in range(currentRange):
            compCount += 1
            if NumList[i] &gt; NumList[i+1]:
                temp = NumList[i]
                NumList[i] = NumList[i+1]
                NumList[i+1] = temp
   # print("Number of comparisons:",compCount)



NumList = ListGenerator(1,200,10)
print("Before running through soriting algorithm\n",NumList)
print("\nAfter running through soriting algorithm")
bubbleSort(NumList)
print(NumList,"\n")
for i in range (0, 10, ++1):
 print("\n&gt;Test run:",i+1)
 bubbleSort(NumList)
 compCount = ((len(NumList))*((len(NumList))-1))/2
 print("Number of comparisons:",compCount)
</code></pre>

<p>run time screen shot 
<a href="http://i.stack.imgur.com/i5M2f.png" rel="nofollow"><img src="http://i.stack.imgur.com/i5M2f.png" alt="enter image description here"></a></p>

<p>It looks like the code just executes incredibly fast. In <code>bubbleSort</code>, I added an additional <code>for</code> loop to execute the comparisons another <code>10000</code> times:</p>

<pre><code>@timeit
def bubbleSort(NumList):
    compCount,copyCount= 0,0

    for i in range(10000):
        for currentRange in range(len(NumList)-1,0,-1):
            for i in range(currentRange):
                compCount += 1
                if NumList[i] &gt; NumList[i+1]:
                    temp = NumList[i]
                    NumList[i] = NumList[i+1]
                    NumList[i+1] = temp
</code></pre>

<p>Now the result is:</p>

<pre><code> ('Before running through soriting algorithm\n', [30, 18, 144, 28, 155, 183, 50, 101, 156, 26])

After running through soriting algorithm
function [bubbleSort] finished in 12 ms
([18, 26, 28, 30, 50, 101, 144, 155, 156, 183], '\n')
('\n&gt;Test run:', 1)
function [bubbleSort] finished in 12 ms
('Number of comparisons:', 45)
('\n&gt;Test run:', 2)
function [bubbleSort] finished in 8 ms
('Number of comparisons:', 45)
('\n&gt;Test run:', 3)
</code></pre>

<p>etc... @vishes_shell points this out in the comments as well.</p>

python timeit