같은객체 계속 반복해서 함수로 넘기니
레퍼런스가 압도적으로 우위!
---------------------------------
#include <iostream>
#include <time.h>
using namespace std;
class Person
{
private:
int num_;
int age_;
string name_;
public:
Person():num_(0),age_(0),name_("Kim"){}
void Increment(){
num_++;
}
void SetName(string name){
name_=name;
}
string GetName(){
return name_;
}
void SetNum(int num){
num=num_;
}
int GetNum(){
return num_;
}
void SetAge(int age){
age_=age;
}
int GetAge(){
return age_;
}
};
void func1(Person p){
p.Increment();
}
void func2(Person& p){
p.Increment();
}
int main()
{
time_t start1=time(NULL);
Person p;
for(int i=0;i<999999999;i++){
func1(p);
}
time_t end1=time(NULL);
cout<<"Value 시간 : "<<end1-start1<<"초"<<endl;
time_t start2=time(NULL);
Person p2;
for(int i=0;i<999999999;i++){
func2(p2);
}
time_t end2=time(NULL);
cout<<"Reference 시간 : "<<end2-start2<<"초"<<endl;
}
복사와참조가 같냐
멍청한 새끼야 캐시도 생각해서 하나하나 따로 실험해라 동시에 한 프로그램에서 연속으로 하지말고.
이런 존내쓸데없는 테스트는 왜하는거지