scipy - Analyzing time complexity of a function written in C -
i implementing longest common subsequence problem in c. wish compare time taken execution of recursive version of solution , dynamic programming version. how can find time taken running lcs function in both versions various inputs? can use scipy plot these values on graph , infer time complexity?
thanks in advance,
razor
for second part of question: short answer yes, can. need 2 data sets (one each solution) in format convenient parse python. like:
x y z
on each line, x sequence length, y time taken dynamic solution, z time taken recursive solution
then, in python:
# load these data sets. sequence_lengths = ... recursive_times = ... dynamic_times = ... import matplotlib.pyplot plt fig = plt.figure() ax = fig.add_subplot(111) p1 = ax.plot(sequence_lengths, recursive_times, 'r', linewidth=2) p2 = ax.plot(sequence_lengths, dynamic_times, 'b', linewidth=2) plt.xlabel('sequence length') plt.ylabel('time') plt.title('lcs timing') plt.grid(true) plt.show()
Comments
Post a Comment