Why comparison of single value tensor with float is much slower than a comparison of tensors item method output with float?
I am optimizing my code and have just seen this behavior. Is it expected?
Example below:
In [7]: one = torch.tensor(1.)
In [8]: %timeit one > 1.5
6.28 µs ± 9.48 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
In [9]: %timeit one.item() > 1.5
562 ns ± 1.18 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
In [19]: %timeit torch.gt(one, 1.5)
6.42 µs ± 18.9 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)