Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from matplotlib import pyplot as plt
- from datetime import datetime
- import random
- import math
- def r_test(n):
- intervals = []
- for _ in range(n):
- start = random.randint(1, n)
- interval_length = random.randint(2, n)
- intervals.append([start, start + interval_length])
- return intervals
- # код и треда
- def anon_f(input):
- input = sorted(input)
- result = []
- while len(input) > 0:
- base = input.pop(0)
- while len(input) > 0 and input[0][0] <= base[1] + 1:
- base = [base[0], max(base[1], input[0][1])]
- input.pop(0)
- result.append(base)
- return result
- def nlogn(n):
- for _ in range(n):
- for __ in range(int(math.log(n))):
- continue
- a = sum(range(n))
- arr = [0] * n
- for i in range(n):
- arr[i] = i or 0
- xs = [n for n in range(1000, 10000, 1)]
- ys = []
- ys_nlog = []
- for x in xs:
- a = r_test(x)
- start = datetime.now()
- anon_f(a)
- y = (datetime.now() - start).total_seconds()
- ys.append(y)
- start = datetime.now()
- nlogn(x)
- y = (datetime.now() - start).total_seconds()
- ys_nlog.append(y)
- print(f"x: {x} time: {y}")
- plt.plot(xs, ys)
- plt.plot(xs, ys_nlog)
- plt.grid()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment