Search code examples
javacastingintmicro-optimization

How expensive it is to cast from int to short in Java


In terms of runtime performance, how expensive it is to cast int to short in Java? There may be thousands of such casting, hence I wonder if it would impact the performance or not. Thanks.


Solution

  • No. It won't impact performances. It is a single simple operation. When you want to analize performances of a software you better focus on the computational cost of algorithmic operations based on the size of input.