正在加载图片...
At the end of the scope.which coincides with the end of the function,the Trace and twostng objects are destroyed 。Destroy the string .The Trace destructor invokes the string destructor for the memberstring. When tracing isoff r object never gets used.Yo pure v tracing is off This was supposed to be the fast lane. int addone (intx /version 0 return x+1; and measured execution time: int main() iveacing o /Start timing o,a86n /stop timing Next.we added aae object to addone and measured again to evaluate the performance delta This is Version 1(see Figure 1): int addone (intx) /version 1.Introducing a Trace object return x 1; Figure 1.1.The performance cost of the Trace object. 4 At the end of the scope, which coincides with the end of the function, the Trace and two string objects are destroyed: • Destroy the string name. • Invoke the Trace destructor. • The Trace destructor invokes the string destructor for the member string. When tracing is off, the string member object never gets used. You could also make the case that the Trace object itself is not of much use either (when tracing is off). All the computational effort that goes into the creation and destruction of those objects is a pure waste. Keep in mind that this is the cost when tracing is off. This was supposed to be the fast lane. So how expensive does it get? For a baseline measurement, we timed the execution of a million iterations of the function addOne(): int addOne(int x) // Version 0 { return x+1; } As you can tell, addOne() doesn't do much, which is exactly the point of a baseline. We are trying to isolate the performance factors one at a time. Our main() function invoked addOne() a million times and measured execution time: int main() { Trace::traceIsActive = false;//Turn tracing off //... GetSystemTime(&t1); // Start timing for (i = 0; i < j; i++) { y = addOne(i); } GetSystemTime(&t2); // Stop timing // ... } Next, we added a Trace object to addOne and measured again to evaluate the performance delta. This is Version 1 (see Figure 1.1): int addOne(int x) // Version 1. Introducing a Trace object { string name = "addOne"; Trace t(name); return x + 1; } Figure 1.1. The performance cost of the Trace object
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有