///////////////////////////////////////////////////////////////////////////// // copy.cpp - demonstrate performance implications of copy // // Jim Fawcett, CSE691 - SW Modeling & Analysis, Fall 2000 ///////////////////////////////////////////////////////////////////////////// // Platform: Dell XPS1000, Windows 2000 Professional, SP1 #include #include "..\timer.h" using namespace std; ///////////////////////////////////////////////////////////////////////////// // defining a big object struct bigArg { char ch[10000]; }; ///////////////////////////////////////////////////////////////////////////// // passing big object by value void copyVal(bigArg a) { static bool first = true; if(first) { cout << "\n copyVal(bigArg a)"; first = false; } char ch = a.ch[0]; ch = a.ch[99]; } ///////////////////////////////////////////////////////////////////////////// // passing big object by reference void copyRef(bigArg &a) { static bool first = true; if(first) { cout << "\n copyRef(bigArg &a)"; first = false; } char ch = a.ch[0]; ch = a.ch[99]; } // ///////////////////////////////////////////////////////////////////////////// // function to time function calls template clock_t timeFunction(U(*pFunc)(V v), V v, int N) { timer t; t.start(); int i; for(i=0; i(copyVal, arg, N); bigArg &argRef = arg; Ttest = timeFunction(copyRef, argRef, N); cout << "\n sizeof(bigArg&) = " << sizeof(&arg); cout << "\n\n"; }