Advertisement
angryatti

Testing thread etc.

Nov 15th, 2023
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.17 KB | None | 0 0
  1. #Based on: Sz. P.
  2. import time
  3. import math
  4. from math import sqrt
  5. import random
  6. import threading
  7.  
  8. class tests:
  9.     def __init__(self):
  10.         self.lessthan1 = []
  11.         self.lessthan2 = []
  12.         self.lessthan3 = []
  13.         self.lessthan4 = []
  14.         self.tomb = []
  15.     def withdot(self):
  16.         starttime=time.time()
  17.         for i in range(1,10000000):
  18.             a=math.sqrt(i)
  19.         print('withdot: \n',time.time()-starttime,'\n')
  20.  
  21.     def withoutdot(self):
  22.         starttime=time.time()
  23.         for i in range(1,10000000):
  24.             a=sqrt(i)
  25.         print('without dot:',time.time()-starttime,'\n')
  26.    
  27.     def loops(self):
  28.         print('loops' ,'\n')
  29.         self.tomb=random.sample(range(0, 100000000), 10000000)
  30.         starttime=time.time()
  31.         self.lessthan1=[i for i in self.tomb if i<50000000]
  32.        
  33.         print('Listiter:',time.time()-starttime ,'\n')
  34.     def range(self):
  35.         starttime=time.time()
  36.         for i in range(0,len(self.tomb)):
  37.             if self.tomb[i]<50000000:
  38.                 self.lessthan2.append(self.tomb[i])
  39.         print('Range:   ',time.time()-starttime,"\n")
  40.     def foreach(self):
  41.         starttime=time.time()
  42.         for i in self.tomb:
  43.             if i<50000000:
  44.                 self.lessthan3.append(i)
  45.         print('foreach: ',time.time()-starttime,"\n")
  46.     def whileofwhile(self):
  47.         i=0
  48.         starttime=time.time()
  49.         while i<len(self.tomb):
  50.             if self.tomb[i]<50000000:
  51.                 self.lessthan4.append(self.tomb[i])
  52.             i+=1
  53.         print('while:   ',time.time()-starttime,"\n")
  54.  
  55. test = tests()
  56. test.withdot()
  57. test.withoutdot()
  58. test.loops()
  59.  
  60. test.range()
  61. test.foreach()
  62. test.whileofwhile()
  63.  
  64. print ("Experimental")
  65.  
  66.  
  67. t1 = threading.Thread(target=test.withdot)
  68. t2 = threading.Thread(target=test.withoutdot)
  69. t3 = threading.Thread(target=test.loops)
  70. t4 = threading.Thread(target=test.range)
  71. t5 = threading.Thread(target=test.foreach)
  72. t6 = threading.Thread(target=test.whileofwhile)
  73. t1.start()
  74. t2.start()
  75. t1.join()
  76. t2.join()
  77. t3.start()
  78. t4.start()
  79. t5.start()
  80. t6.start()
  81.  
  82. t3.join()
  83. t4.join()
  84. t5.join()
  85. t6.join()
  86. print("Test Finshed")
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement