Skip to content

Commit f0654dc

Browse files
committed
compare timing of inv, pinv and solve
1 parent d9212bb commit f0654dc

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎spatialmath/timing.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,21 @@ def result(op, t):
221221
a = np.r_[1.0, 2.0, 3.0]
222222
b = np.r_[-5.0, 4.0, 3.0]
223223
224+
A = np.random.randn(6,6)
225+
As = (A + A.T) / 2
226+
bb = np.random.randn(6)
224227
'''
225228
table.rule()
226229

230+
t = timeit.timeit(stmt='c = np.linalg.inv(As)', setup=misc_setup, number=N)
231+
result("np.inv(As)", t)
232+
233+
t = timeit.timeit(stmt='c = np.linalg.pinv(As)', setup=misc_setup, number=N)
234+
result("np.pinv(As)", t)
235+
236+
t = timeit.timeit(stmt='c = np.linalg.solve(As, bb)', setup=misc_setup, number=N)
237+
result("np.solve(As, b)", t)
238+
227239
t = timeit.timeit(stmt='c = np.cross(a,b)', setup=misc_setup, number=N)
228240
result("np.cross()", t)
229241

0 commit comments

Comments
 (0)