Keksike

2 лаба Малина

Oct 11th, 2021 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | None | 0 0
  1. from random import randint
  2. import time
  3.  
  4. def sozdanie(a):
  5.     file_test = open("file.txt", "w")
  6.     for i in range(a):
  7.         number = randint(0,10000)
  8.         file_test.write(str(number) + '\n')
  9.     file_test.close()
  10.     return 0
  11.  
  12. def vstavka(list):
  13.     p = 0
  14.     for i in range(len(list)):
  15.         j = i-1
  16.         key = list[i]
  17.         while list[j] > key and j >= 0:
  18.             list[j+1] = list[j]
  19.             j -= 1
  20.         list[j+1] = key
  21.         if (i%1000) == 0:
  22.             p += 10
  23.             print(p, "%")
  24.     return(list)
  25.  
  26. def chtenie(a):
  27.     p = 0
  28.     count = 0
  29.     with open("file.txt") as f:
  30.         for line in f:
  31.             a.append([int(x) for x in line.split()])
  32.             count += 1
  33.             if (count%1000) == 0:
  34.                 p += 10
  35.                 print(p, "%")
  36.     return(a)
  37.  
  38. def schet(list):
  39.     sum = 0
  40.     sr = 0
  41.     p = 0
  42.     for i in range(10000-1):    
  43.         sum += int(data1[i])
  44.         sr = sum / (1+i)
  45.         if (i%1000) == 0:
  46.             p += 10
  47.             print(p, "%")
  48.     return(sum, sr)
  49.  
  50. def tablichka(a, b, c, d):
  51.     x = ' '
  52.  
  53.     print('{0}'.format('Name'), (8*x), '  {0}        {1}       {2}'.format('PC1', 'PC2', 'Your PC'), '\n')
  54.     print('{0}'.format('Calculating'),(x), '{0}   {1}    {2:.2f}'.format('18563.53' , '19152.91' , a), '\n')
  55.     print('{0}'.format('Memory'),(6*x), '{0}   {1}    {2:.2f}'.format('29942.14' , '31473.45' , b), '\n')
  56.     print('{0}'.format('Graphics'),(4*x), '{0}   {1}    {2:.2f}'.format('18475.39' , '17656.24', c), '\n')
  57.     print('{0}'.format('Result'),(6*x), '{0}   {1}    {2:.2f}'.format('22327.02' , '22760.53', d), '\n')
  58.     return 0
  59.  
  60. #sozdanie(10000)
  61.  
  62. data = []
  63. data1 = []
  64.  
  65. print("Hello, it`s time to start benchmark")
  66.  
  67. start_chtenie = time.time()
  68. chtenie(data)
  69. stop_chtenie = time.time()
  70. s_c = (stop_chtenie-start_chtenie)*300000
  71. print("prochital, otcenka graphic - ", s_c)
  72.  
  73. start_sortirovka = time.time()
  74. vstavka(data)
  75. stop_sortirovka = time.time()
  76. s_v = (stop_sortirovka-start_sortirovka)*1000
  77. print("otsortiroval, otcenka memory - ", s_v)
  78.  
  79. for row in data:
  80.     data1.append(' '.join(map(str, row)))
  81.  
  82. start_schet = time.time()
  83. sum, sr = schet(data1)
  84. stop_schet = time.time()
  85. s_s = (stop_schet-start_schet)*900000
  86. print("poschital, otcenka calculating - ", s_s)
  87.  
  88. print("itogoviy resultat - ", ((s_c + s_v + s_s)/3), '\n')
  89.  
  90. tablichka(s_s, s_c, s_v, ((s_c + s_v + s_s)/3))
Advertisement
Add Comment
Please, Sign In to add comment