Matrix chain multiplication: Difference between revisions
Content added Content deleted
Line 161: | Line 161: | ||
print(a) |
print(a) |
||
print() |
print() |
||
print("function time |
print("function time cost parens ") |
||
print("-" * 90) |
print("-" * 90) |
||
for f in [optim1, optim2, optim3]: |
for f in [optim1, optim2, optim3]: |
||
Line 167: | Line 167: | ||
s, u = f(a) |
s, u = f(a) |
||
t2 = time.clock() |
t2 = time.clock() |
||
print("%s %10.3f % |
print("%s %10.3f %10d %s" % (f.__name__, 1000 * (t2 - t1), s, u)) |
||
print()</lang> |
print()</lang> |
||
Line 175: | Line 175: | ||
[1, 5, 25, 30, 100, 70, 2, 1, 100, 250, 1, 1000, 2] |
[1, 5, 25, 30, 100, 70, 2, 1, 100, 250, 1, 1000, 2] |
||
function time |
function time cost parens |
||
------------------------------------------------------------------------------------------ |
------------------------------------------------------------------------------------------ |
||
optim1 |
optim1 838.636 38120 [[[[[[[[0, 1], 2], 3], 4], 5], 6], [7, [8, 9]]], [10, 11]] |
||
optim2 80. |
optim2 80.628 38120 [[[[[[[[0, 1], 2], 3], 4], 5], 6], [7, [8, 9]]], [10, 11]] |
||
optim3 0. |
optim3 0.373 38120 [[[[[[[[0, 1], 2], 3], 4], 5], 6], [7, [8, 9]]], [10, 11]] |
||
[1000, 1, 500, 12, 1, 700, 2500, 3, 2, 5, 14, 10] |
[1000, 1, 500, 12, 1, 700, 2500, 3, 2, 5, 14, 10] |
||
function time |
function time cost parens |
||
------------------------------------------------------------------------------------------ |
------------------------------------------------------------------------------------------ |
||
optim1 223. |
optim1 223.186 1773740 [0, [[[[[[1, 2], 3], [[[4, 5], 6], 7]], 8], 9], 10]] |
||
optim2 27. |
optim2 27.660 1773740 [0, [[[[[[1, 2], 3], [[[4, 5], 6], 7]], 8], 9], 10]] |
||
optim3 0. |
optim3 0.307 1773740 [0, [[[[[[1, 2], 3], [[[4, 5], 6], 7]], 8], 9], 10]] |
||
</pre> |
</pre> |