Skip to content

Instantly share code, notes, and snippets.

@ykdojo
Created July 6, 2018 23:48
Show Gist options
  • Save ykdojo/bb35c454eaabaf52c0de71fb8978db70 to your computer and use it in GitHub Desktop.
Save ykdojo/bb35c454eaabaf52c0de71fb8978db70 to your computer and use it in GitHub Desktop.
import time
Ts = []
Ns = []
for multiple in range(1, 11):
N = 10 * multiple
Ns.append(N)
STR_LENGTH = 3000
root = Node('a'*STR_LENGTH)
current = root
N_trials = 10
T_samples = []
for i in range(N_trials):
for j in range(N):
node = Node('a'*STR_LENGTH)
current.left = node
current = node
start = time.time()
serialize(root)
end = time.time()
T = end - start
T_samples.append(T)
T = sum(T_samples) / N_trials
Ts.append(T)
from matplotlib import pyplot as plt
plt.plot(Ns, Ts)
print(Ts)
Ts[-1] / Ts[0] # this ration should be about 10 if this is O(N)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment