Ask Your Question
1

How to measure clock cycles for a particular operation

asked 2022-02-07 08:19:58 +0200

Sanu gravatar image

updated 2022-02-08 00:04:11 +0200

slelievre gravatar image

How to measure clock cycles in the following matrix multiplication?

A = zero_matrix(ZZ,100)
B = zero_matrix(ZZ,100)
for i in range(100):
    for j in range(100):
        A[i, j] = ZZ.random_element(1000)
        B[i, j] = ZZ.random_element(1000)
C = A * B
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2022-02-07 21:39:34 +0200

To measure how much time a command takes, you can use either %time or %timeit:

sage: A = zero_matrix(ZZ,100); B = zero_matrix(ZZ, 100)
sage: for i in range(100):
....:     for j in range(100):
....:         A[i,j] = ZZ.random_element(1000)
....:         B[i,j] = ZZ.random_element(1000)
....: 
sage: %time A*B # this runs the command once and returns its result + timing info
CPU times: user 523 µs, sys: 0 ns, total: 523 µs
Wall time: 525 µs
100 x 100 dense matrix over Integer Ring (use the '.str()' method to see the entries)
sage: %timeit A*B # runs the command multiple times
481 µs ± 763 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)

For help, evaluate %time? or %timeit?, and see also the relevant Sage Reference manual page.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-02-07 08:19:58 +0200

Seen: 114 times

Last updated: Feb 08 '22