Created
May 9, 2023 18:12
-
-
Save liangfu/e1c82189dd1fa779f4432935d0a7e328 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import time | |
import math | |
def burn_cpu(): | |
a = np.random.rand(1024, 1024) | |
b = np.random.rand(1024, 1024) | |
tic = time.time() | |
c = np.dot(a, b) | |
toc = time.time() | |
elapsed = (toc-tic)*1000 | |
seconds = 5 | |
times = int(math.floor((1000/elapsed) * seconds)) | |
print(f"elapsed: {elapsed:.1f} ms") | |
print(f"running {times} times") | |
tic = time.time() | |
for _ in range(times): | |
c = np.dot(a, b) | |
toc = time.time() | |
elapsed = (toc-tic)*1000 | |
print(f"elapsed: {elapsed:.1f} ms") | |
if __name__=="__main__": | |
burn_cpu() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment