python timeit() and randint test results so far
Update: timeit has a default and runs the tested method 1 million times!!!!
Update: 1-6-18 a few more tests done, one that took 4 hours, and a few outside the python virtual env.
Made some tests. Wanted to eliminate my DLList, and the bubble_sort as the dirty gremlins in the machine.
I think they are a part of why it crashed, but not because they are buggy. I think when randint gets together with timeit, they just overload, and if randint is interacting with the DLList and it's an import even more shenanigans take place within the timeit. My system can't do it. I would need to test it on a clean system to see if it's me or not. Powershell also crashed with the original file, so it's not just WSL.
I can't seem to find anyone else having an issue with timeit and randint.
But these numbers can't be right.... That or there's something I am doing completely wrong.
# this says there might be some other process making test times too long
#...but it looks like I'm doing it right.
http://www.diveintopython.net/performance_tuning/timeit.html
I just can't seem to find anything that makes reference to timeit() crashing the command line, and my OS was not happy either.
Here's my test... Thought about making one that would run all night... Kinda want to buy a new laptop.... and not really fond of the OS on this thing..... I could reload it all. Another learning experience.....
theory.py
from random import randint
alist = []
def spam(x):
y = x + 1
return y
def test_spam():
# TEST 10
foo = 41
for i in range(0, 299):
x = randint(0, 10)
spam(foo)
### tests ran in WSL through /mnt/c/Users/../../../theory.py
### $ python theory.py
### Time in seconds
##### test 12 [16389.59] ###
#for i in range(0, 3000):
#x = randint(0, 10)
#estimate 4-5 hours in virtual env.
##### test 11 [28.17] ###
#foo = 41
#for i in range(0, 299):
#x = i + 1
#spam(foo)
##### test 10 [1632.13] ###
#foo = 41
#for i in range(0, 299):
#x = randint(0, 10)
#spam(foo)
#test 10B[885.50]#
#no virtual env. estimate 950-1000s
##### test 9 [278.05] ###
#foo = 41
#for i in range(0, 50):
#x = randint(0, 10)
#spam(foo)
#test 9B [151.21]#
# no virtual env. #
##### test 8 [56.40] ###
#foo = 41
#for i in range(0, 10):
#x = randint(0, 10)
#spam(foo)
#test 8B [ 33.91]#
# no virtual env. #
##### test 7 [63.17] ###
#foo = 41
#for i in range(0, 10):
#x = randint(0, 10)
#alist.append(x)
#spam(foo)
#test 7B [ 38.33]#
#no virtual env. #
##### test 6 [6.68] ###
#carrots = randint(-3000, 3000)
#spam(carrots)
##### test 5 [6.57] ###
#carrots = randint(0, 3000)
#spam(carrots)
#test 5B [3.68] no virtual env.#
##### test 4 [5.87] ###
#carrots = randint(0, 30)
#spam(carrots)
#test 4B [3.55] no virtual env.#
###### test 3 [6.05] ###
#carrots = randint(0, 5)
#spam(carrots)
###### test 2 [6.10] ###
#carrots = randint(0, 10)
#spam(carrots)
###### test 1 [0.5] ###
# no randint
#spam(8)
#test 1B [0.43] no virtual env.#
# test 1, no randint 0.5
# test 2, randint(0, 10) 6.10
# test 3, randint(0, 5) 6.05
# test 4, randint(0, 30) 5.87
# test 5, randint(0, 3000) 6.57
# test 6, randint(-3000, 3000), 6.68
# test 7, for loop, randint, python list append * 11... 63.17
# test 8, same as 7, for loop run 11*, x = randint(0, 10) no python list. 56.40
# test 9, for loop set to run 51 times, x = randint(0, 10) spam unchanged. 278.05
# test 10, for loop set to run 300 times, x = randint(0, 10) spam unchanged. 1632.13
# test 11, for loop set to run 300* no randint, spam unchanged. 28.17
# test 12. for loop set to run 3001* randint, spam unchanged, 16386.59
if __name__ == '__main__':
import timeit
print(timeit.timeit("test_spam()", setup="from __main__ import test_spam"))
Update: 1-6-18 a few more tests done, one that took 4 hours, and a few outside the python virtual env.
Made some tests. Wanted to eliminate my DLList, and the bubble_sort as the dirty gremlins in the machine.
I think they are a part of why it crashed, but not because they are buggy. I think when randint gets together with timeit, they just overload, and if randint is interacting with the DLList and it's an import even more shenanigans take place within the timeit. My system can't do it. I would need to test it on a clean system to see if it's me or not. Powershell also crashed with the original file, so it's not just WSL.
I can't seem to find anyone else having an issue with timeit and randint.
But these numbers can't be right.... That or there's something I am doing completely wrong.
# this says there might be some other process making test times too long
#...but it looks like I'm doing it right.
http://www.diveintopython.net/performance_tuning/timeit.html
I just can't seem to find anything that makes reference to timeit() crashing the command line, and my OS was not happy either.
Here's my test... Thought about making one that would run all night... Kinda want to buy a new laptop.... and not really fond of the OS on this thing..... I could reload it all. Another learning experience.....
theory.py
from random import randint
alist = []
def spam(x):
y = x + 1
return y
def test_spam():
# TEST 10
foo = 41
for i in range(0, 299):
x = randint(0, 10)
spam(foo)
### tests ran in WSL through /mnt/c/Users/../../../theory.py
### $ python theory.py
### Time in seconds
##### test 12 [16389.59] ###
#for i in range(0, 3000):
#x = randint(0, 10)
#estimate 4-5 hours in virtual env.
##### test 11 [28.17] ###
#foo = 41
#for i in range(0, 299):
#x = i + 1
#spam(foo)
##### test 10 [1632.13] ###
#foo = 41
#for i in range(0, 299):
#x = randint(0, 10)
#spam(foo)
#test 10B[885.50]#
#no virtual env. estimate 950-1000s
##### test 9 [278.05] ###
#foo = 41
#for i in range(0, 50):
#x = randint(0, 10)
#spam(foo)
#test 9B [151.21]#
# no virtual env. #
##### test 8 [56.40] ###
#foo = 41
#for i in range(0, 10):
#x = randint(0, 10)
#spam(foo)
#test 8B [ 33.91]#
# no virtual env. #
##### test 7 [63.17] ###
#foo = 41
#for i in range(0, 10):
#x = randint(0, 10)
#alist.append(x)
#spam(foo)
#test 7B [ 38.33]#
#no virtual env. #
##### test 6 [6.68] ###
#carrots = randint(-3000, 3000)
#spam(carrots)
##### test 5 [6.57] ###
#carrots = randint(0, 3000)
#spam(carrots)
#test 5B [3.68] no virtual env.#
##### test 4 [5.87] ###
#carrots = randint(0, 30)
#spam(carrots)
#test 4B [3.55] no virtual env.#
###### test 3 [6.05] ###
#carrots = randint(0, 5)
#spam(carrots)
###### test 2 [6.10] ###
#carrots = randint(0, 10)
#spam(carrots)
###### test 1 [0.5] ###
# no randint
#spam(8)
#test 1B [0.43] no virtual env.#
# test 1, no randint 0.5
# test 2, randint(0, 10) 6.10
# test 3, randint(0, 5) 6.05
# test 4, randint(0, 30) 5.87
# test 5, randint(0, 3000) 6.57
# test 6, randint(-3000, 3000), 6.68
# test 7, for loop, randint, python list append * 11... 63.17
# test 8, same as 7, for loop run 11*, x = randint(0, 10) no python list. 56.40
# test 9, for loop set to run 51 times, x = randint(0, 10) spam unchanged. 278.05
# test 10, for loop set to run 300 times, x = randint(0, 10) spam unchanged. 1632.13
# test 11, for loop set to run 300* no randint, spam unchanged. 28.17
# test 12. for loop set to run 3001* randint, spam unchanged, 16386.59
if __name__ == '__main__':
import timeit
print(timeit.timeit("test_spam()", setup="from __main__ import test_spam"))
Comments
Post a Comment