속도에 큰 차이는 없으니 걍 게터세터 써도 될듯 ㅋ
속도차는 밀리세컨이아니라 그냥 초임
--------------------------------------------------
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
class Normal
{
public:
int a;
int b;
int c;
int d;
int e;
string s1;
string s2;
string s3;
string s4;
string s5;
};
class GetAndSet
{
private:
int a;
int b;
int c;
int d;
int e;
string s1;
string s2;
string s3;
string s4;
string s5;
public:
int GetA(){return a;}
int GetB(){return a;}
int GetC(){return a;}
int GetD(){return a;}
int GetE(){return a;}
void SetA(int n){a=n;}
void SetB(int n){b=n;}
void SetC(int n){c=n;}
void SetD(int n){d=n;}
void SetE(int n){e=n;}
string GetS1(){return s1;}
string GetS2(){return s2;}
string GetS3(){return s3;}
string GetS4(){return s4;}
string GetS5(){return s5;}
void SetS1(const string& s){s1=s;}
void SetS2(const string& s){s2=s;}
void SetS3(const string& s){s3=s;}
void SetS4(const string& s){s4=s;}
void SetS5(const string& s){s5=s;}
};
void main()
{
time_t start,end;
int a,b,c,d,e;
string s1="One",s2="two",s3="three",s4="four",s5="five";
start=time(NULL);
Normal normal;
for(int i=0;i<99999999;i++){
normal.a=i;
normal.b=i;
normal.c=i;
normal.d=i;
normal.e=i;
a=normal.a;
b=normal.b;
c=normal.c;
d=normal.d;
e=normal.e;
normal.s1=s1;
normal.s2=s2;
normal.s3=s3;
normal.s4=s4;
normal.s5=s5;
s1=normal.s1;
s2=normal.s2;
s3=normal.s3;
s4=normal.s4;
s5=normal.s5;
}
end=time(NULL);
cout<<"Normal : "<<end-start<<endl;
start=time(NULL);
GetAndSet and;
for(int i=0;i<99999999;i++){
and.SetA(i);
and.SetB(i);
and.SetC(i);
and.SetD(i);
and.SetE(i);
a=and.GetA();
b=and.GetB();
c=and.GetC();
d=and.GetD();
e=and.GetE();
and.SetS1(s1);
and.SetS2(s2);
and.SetS3(s3);
and.SetS4(s4);
and.SetS5(s5);
s1=and.GetS1();
s2=and.GetS2();
s3=and.GetS3();
s4=and.GetS4();
s5=and.GetS5();
}
end=time(NULL);
cout<<"GetAndSet : "<<end-start<<endl;
}
자바에서 내부 클래스 사용할때 private member에 접근하는 속도가 느리다고 했음.
Getter, Setter를 public member로 바꾸는건 보통 임베디드 기기용 프로그래밍에서 속도최적화를 위해 하는것. 일반 pc로 벤치마킹 했으니 당연히 속도차가 별로 없지
겟셋은 속도를 생각하지 않고 쓰는거 아님?
실수로 잘못된값 들어와서 씹창나는거 방지할라고 쓰는거
-_- 이상한 테스트를 하네 이사람 ㅋㅋㅋ
대체 이런 테스트를 왜하는건지? 테스트를 PC에서 했는데, 요즘 PC용 컴파일러들이 허접한것도 아니고 저런 getter/setter정도는 다 인라인화해주지 않음? Release로 바꾸고 컴파일 때리면 속도차이 없을듯.
내가하는 테스트는 다 release임
아하 돌려보니까 차이가 나긴 남.
뭐 이딴 병신같은 테스트가다있지?
수고햇음.. 의미는없지만 ㅋㅋ