Java method call vs 변수 사용 cpu 성능 (set / get)
Java 에서 static method call 과 static 멤버 변수르 사용 성능을 확인
예상대로의 결론
static member 로 참조하는 것이 10배 정도 빠르다.
Test Code #1 : Static class(sigleton) method call
long startTime = System.currentTimeMillis();
for(;cnt < 1000000; cnt++){
if(StaticTestClass.instance().isOn()){
StaticTestClass.instance().setOnOff(true);
}
else{
StaticTestClass.instance().setOnOff(false);
}
}
long endTime = System.currentTimeMillis();
Log.e("@@@@@@2222@@@@@@@@@@@@@@@@cost:" + (endTime - startTime) + "@@@@@@@@@@@@@@");
=> Result
@@@@@@@@@@@@@@@@@@@@@@cost:4825@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@cost:4863@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@cost:5027@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@cost:4962@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@cost:5041@@@@@@@@@@@@@@
Test Code #2
long startTime = System.currentTimeMillis();
for(;cnt < 1000000; cnt++){
if(mTestOnOff){
mTestOnOff = false;
}
else{
mTestOnOff = true;
}
}
long endTime = System.currentTimeMillis();
Log.e("@@@@@@2222@@@@@@@@@@@@@@@@cost:" + (endTime - startTime) + "@@@@@@@@@@@@@@");
=> Result :
@@@@@@2222@@@@@@@@@@@@@@@@cost:472@@@@@@@@@@@@@@
@@@@@@2222@@@@@@@@@@@@@@@@cost:455@@@@@@@@@@@@@@
@@@@@@2222@@@@@@@@@@@@@@@@cost:435@@@@@@@@@@@@@@
그래서 마지막으로 static class 의 sigleton의 member를 static public 으로 변경하여 성능 측정을 해봤다.
for문에 아래 부분만 변경했을 때
long startTime = System.currentTimeMillis();
for(;cnt < 1000000; cnt++){
StaticTestClass.mIsEngineOn = false;
}
else{
StaticTestClass.mIsEngineOn = true;
}
}
long endTime = System.currentTimeMillis();
Log.e("@@@@@@2222@@@@@@@@@@@@@@@@cost:" + (endTime - startTime) + "@@@@@@@@@@@@@@");
=> Result :
다른 좋은 방법이나 위 사항에 대한 태클 환영햡니다.
'IT > Android[안드로이드]' 카테고리의 다른 글
[Android Studio] Generate JavaDoc (0) | 2019.09.26 |
---|---|
GIT 이해하기 쉬운 게임 사이트 (0) | 2014.09.12 |
Ubuntu client Android 빌드 환경 구현 (1) | 2014.08.08 |
Ubuntu 12.04/12.10 Server Android Full 빌드 환경 만들기 (0) | 2014.05.04 |
Could not open Selected VM debug port (8700) - 해결[Solved] (0) | 2013.05.04 |