Skip to content

Instantly share code, notes, and snippets.

@yaroslavvb
Created October 29, 2017 22:30
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 yaroslavvb/2029469e04347997a67580e2b7540770 to your computer and use it in GitHub Desktop.
Save yaroslavvb/2029469e04347997a67580e2b7540770 to your computer and use it in GitHub Desktop.
import torch
import numpy as np
import time
def benchmark():
SIZE_GB = 1
num_iters = 100
def compute():
a = torch.ones(int(SIZE_GB*1000*250000)).cuda()
b = torch.ones(int(SIZE_GB*1000*250000)).cuda()
for i in range(num_iters):
b+=a
return b
compute() # pre-warm
start = time.perf_counter()
result = compute()[0]
elapsed_ms = (time.perf_counter()-start)*1000
print('result after %d iters: %d' % (num_iters, result,))
print("%d additions of %.3f GB in %.3f ms (%.3f per addition)"%(num_iters,
SIZE_GB,
elapsed_ms,
elapsed_ms/num_iters))
if __name__=='__main__':
benchmark()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment