You could use the pytorch bottleneck 22 to do so.
Note: if you want to do timing like this, you need to call
torch.cuda.synchronize() 

before calling time.time() due to the asynchronous behavior of cuda operations.