Skip to content

Instantly share code, notes, and snippets.

@liangfu
Created May 9, 2023 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liangfu/e1c82189dd1fa779f4432935d0a7e328 to your computer and use it in GitHub Desktop.
Save liangfu/e1c82189dd1fa779f4432935d0a7e328 to your computer and use it in GitHub Desktop.
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