Added brainfart. /JL

This commit is contained in:
Jan Lerking
2023-06-13 13:14:40 +02:00
parent c61b18ec93
commit fbf726896b
2 changed files with 58 additions and 1 deletions

57
brainfart.py Normal file
View File

@@ -0,0 +1,57 @@
import timeit
from memory_profiler import profile
@profile
class BrainFart:
"""
Class to test for benefit of replacing all local
variables, in favor of instanciated variable space in the class it self.
"""
def __init__(self):
self.__reset_locals()
def __reset_locals(self):
self.local1 = None
self.local2 = None
self.local3 = None
self.local4 = None
self.local5 = None
self.local6 = None
self.local7 = None
self.local8 = None
self.local9 = None
self.local10 = None
@profile
def test_with_local_var(self):
loc1 = [x for x in range(10)]
loc2 = [y for y in range(10)]
loc3 = [z for z in range(10)]
loc4 = [x for x in range(10)]
loc5 = [y for y in range(10)]
loc6 = [z for z in range(10)]
loc7 = [x for x in range(10)]
loc8 = [y for y in range(10)]
loc9 = [z for z in range(10)]
loc10 = [x for x in range(10)]
@profile
def test_without_local_var(self):
self.local1 = [x for x in range(10)]
self.local2 = [y for y in range(10)]
self.local3 = [z for z in range(10)]
self.local4 = [x for x in range(10)]
self.local5 = [y for y in range(10)]
self.local6 = [z for z in range(10)]
self.local7 = [x for x in range(10)]
self.local8 = [y for y in range(10)]
self.local9 = [z for z in range(10)]
self.local10 = [x for x in range(10)]
self.__reset_locals()
if __name__ == "__main__":
bf = BrainFart()
#print(timeit.timeit(bf.test_with_local_var))
#print(timeit.timeit(bf.test_without_local_var))
bf.test_with_local_var()
bf.test_without_local_var()

View File

@@ -24,7 +24,7 @@ class Group:
self.members.append(Person(*args))
# Return the last member added
return self.members[-1]
if __name__ == '__main__':
#person = Person("John", 36)
#person.say_hello()