Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Based on: Sz. P.
- import time
- import math
- from math import sqrt
- import random
- import threading
- class tests:
- def __init__(self):
- self.lessthan1 = []
- self.lessthan2 = []
- self.lessthan3 = []
- self.lessthan4 = []
- self.tomb = []
- def withdot(self):
- starttime=time.time()
- for i in range(1,10000000):
- a=math.sqrt(i)
- print('withdot: \n',time.time()-starttime,'\n')
- def withoutdot(self):
- starttime=time.time()
- for i in range(1,10000000):
- a=sqrt(i)
- print('without dot:',time.time()-starttime,'\n')
- def loops(self):
- print('loops' ,'\n')
- self.tomb=random.sample(range(0, 100000000), 10000000)
- starttime=time.time()
- self.lessthan1=[i for i in self.tomb if i<50000000]
- print('Listiter:',time.time()-starttime ,'\n')
- def range(self):
- starttime=time.time()
- for i in range(0,len(self.tomb)):
- if self.tomb[i]<50000000:
- self.lessthan2.append(self.tomb[i])
- print('Range: ',time.time()-starttime,"\n")
- def foreach(self):
- starttime=time.time()
- for i in self.tomb:
- if i<50000000:
- self.lessthan3.append(i)
- print('foreach: ',time.time()-starttime,"\n")
- def whileofwhile(self):
- i=0
- starttime=time.time()
- while i<len(self.tomb):
- if self.tomb[i]<50000000:
- self.lessthan4.append(self.tomb[i])
- i+=1
- print('while: ',time.time()-starttime,"\n")
- test = tests()
- test.withdot()
- test.withoutdot()
- test.loops()
- test.range()
- test.foreach()
- test.whileofwhile()
- print ("Experimental")
- t1 = threading.Thread(target=test.withdot)
- t2 = threading.Thread(target=test.withoutdot)
- t3 = threading.Thread(target=test.loops)
- t4 = threading.Thread(target=test.range)
- t5 = threading.Thread(target=test.foreach)
- t6 = threading.Thread(target=test.whileofwhile)
- t1.start()
- t2.start()
- t1.join()
- t2.join()
- t3.start()
- t4.start()
- t5.start()
- t6.start()
- t3.join()
- t4.join()
- t5.join()
- t6.join()
- print("Test Finshed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement