같은객체 계속 반복해서 함수로 넘기니

레퍼런스가 압도적으로 우위!


---------------------------------


#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;
}