Ask Your Question
1

How to measure clock cycles for a particular operation

asked 3 years ago

Sanu gravatar image

updated 3 years ago

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
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 3 years ago

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.

Preview: (hide)
link

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: 3 years ago

Seen: 226 times

Last updated: Feb 08 '22