CUDA operations are executed asynchronously, so you would have to synchronize the code before starting and stopping the timer. Alternatively, you could also use the torch.utils.benchmark utility, which would synchronize the code for you and also add warmup iterations for a proper profiling.