JVM/JAVA
[JAVA] '++' 와 '+=1' 의 속도 차이
글을 쓰는 개발자
2021. 10. 22. 21:01
반응형
public class Pad {
public static void main(String[] args){
long start = System.currentTimeMillis();
int count = Integer.MAX_VALUE;
long ret = 0L;
for (int i = 0; i < count; i++) {
ret++;
}
long end = System.currentTimeMillis();
System.out.println((end-start)/1000.0);
}
}

public class Pad {
public static void main(String[] args){
long start = System.currentTimeMillis();
int count = Integer.MAX_VALUE;
long ret = 0L;
for (int i = 0; i < count; i++) {
ret+=1;
}
long end = System.currentTimeMillis();
System.out.println((end-count)/1000.0);
}
}

결론: 결과는 유사하게 나온다.
우선 같은 이유는 컴파일 시에 같은 바이트코드로 변환된다는 점. 그래서 비슷한 결과값을 가진다.
뻘 짓 끝
반응형