Timeit has a default... it runs things 1 million times....

Update 1-7-2018:
My CPU does not have the memory.  Found the gremlin!  Finally got one of the bastards! My laptop definitely needs a spring cleaning. Maybe it's time.

The crash isn't because of randint... it's because it's building a 30 node DLList one million times,  each integer in the list can be from 0 to 100,  so besides my processor being slow.... my computer memory just can not handle it.  In the original code, timeit is trying to do this, on top of the bubble sort, one million times on those one million lists... there is no way my computer can do it,  When I take the random_list out of the test,  it can handle doing the bubble sort on the one list, one million times, it's not storing all those integers to memory....













from random import randint
import math
import time
from ex16DLL import*


max_numbers = 30

def random_list(count):
    spam = DLList()
    for i in range(count, 0, -1):
        spam.push(randint(0, 100))
    return spam


def spam(x):
    y = x + 1
    return y

def test_spam():
    alist = random_list(max_numbers)
 
 

###  tests ran in powershell NO virtual environment installed
### tests ran in windows 10 powershell(x86)
### $ python theory2.py

##### test 16 [0.008] ###
     # the piece that broke my original code
     #alist = random_list(max_numbers)
     # number=1
        # 16B number = 10 [0.003]#
        # 16C number = 100 [0.03]#
        # 16D number = 1000 [0.3]#
        # 16E number = 10000 [3.11]#
        # 16F number = 100000 [30.44]#
        # 16G number = 1000000 [crash- not enough memory]  MemoryError #



Update: tonight:

So, I just found a Stackoverflow, and lost the link,  it says it has a default number of times it runs....

So I plugged in the keyword argument at the end, number=1, and got a much more accurate measurement for one run of the biggest one.


       for i in range(0, 3000):
           x = randint(0, 10)

   I got a time of : 0.016             [[    0.016 * 1,000,000  = 16000  ]]
 
So why did it crash with randint?????

Or did it crash because it had an extra function to run into????

Well FML...   I do love to find stuff the hard way.   Well HELL.

                                                theory2.py 

from random import randint
import math
import time
# I think timeit uses random in some way...
# I see it does use time,  so going to test that.

alist = []

def spam(x):
    y = x + 1
    return y

def test_spam():
 
    foo = 41
    for i in range(0, 299):
        x = i + 1
    spam(foo)
 
 

###  tests ran in powershell NO virtual environment installed
### tests ran in windows 10 powershell(x86)
### $ python theory2.py

##### test15 [788.93, 788.52] ###  
    #for i in range(0, 299):
        #x = time.process_time()
        #print(x) in a different file without timeit
    ## estimate 1526s
    ## I think timeit is processing random import
    ## and randint while calculating the randint process...
    ## separate from timeit running the loop took 0.046875
    # loop 1 x = 0.09375
    # loop 299 x = 0.140625

##### test 14 [195.95] ###
    #foo = 7
    #for i in range(1, 300):
        #x = math.floor(7/i)

##### test 13 [79.6] ###
    #foo = "spam"
    #for i in range(0, 299):
        #x = hash(foo)


##### test 12  ###
    #for i in range(0, 3000):
       #x = randint(0, 10)

##### test 11 [38.89]  ###
    #foo = 41
    #for i in range(0, 299):
        #x = i + 1
    #spam(foo)

##### test 10 [1526.47]  ###
    #foo = 41
    #for i in range(0, 299):
        #x = randint(0, 10)
    #spam(foo)

##### test 9 [263.29] ###
    #foo = 41
    #for i in range(0, 50):
        #x = randint(0, 10)
    #spam(foo)

##### test 8 [54.25] ###
    #foo = 41
    #for i in range(0, 10):
        #x = randint(0, 10)
    #spam(foo)

##### test 7 [57.99] ###
    #foo = 41
    #for i in range(0, 10):
        #x = randint(0, 10)
        #alist.append(x)
    #spam(foo)


##### test 6 [6.09]  ###
    #carrots = randint(-3000, 3000)
    #spam(carrots)


##### test 5 [6.22]  ###
    #carrots = randint(0, 3000)
    #spam(carrots)


##### test 4 [5.56]  ###
    #carrots = randint(0, 30)
    #spam(carrots)


###### test 3 [5.87]  ###
    #carrots = randint(0, 5)
    #spam(carrots)

###### test 2 [5.94]  ###
    #carrots = randint(0, 10)
    #spam(carrots)

###### test 1 [0.58]  ###
    # no randint
    #spam(8)

###  WSL RESULSTS IN VIRTUAL ENVIRONMENT:
# test 1,  0.5  missing third digit, didn't record it.
# test 2,  6.10
# test 3,  6.05
# test 4,  5.87
# test 5,  6.57
# test 6,  6.68
# test 7,  63.17
# test 8,  56.40
# test 9,  278.05
# test 10,  1632.13
# test 11,  28.17
# test 12,  16386.59



if __name__ == '__main__':
    import timeit
    print(timeit.timeit("test_spam()", setup="from __main__ import test_spam"))






Comments

Popular posts from this blog

JavaScript Ascii animation with while loops and console.log

playing with trigonometry sin in pygame

JavaScript and a Matrix