-
-
Save ykdojo/bb35c454eaabaf52c0de71fb8978db70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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