正在加载图片...
3,500 2 55 0 Version 0 Version 1 The cost of the for loon has skvrocketed from 55 ms to 3 500 ms In othe ords the eed of addone has plummeted by a factor of more than 60.This kind of overhead will wreak havoc on the performance of any ware.The The Recovery Plan The performance recovery plan was to eliminate objects and computations whose values get dropped when a pointer int addone(int x) return x+l; theFunctionName (name)//Version 2 Similarly,the Trace::debug()method was modified as well to acceptaochar as an input argument instead of asng.Now we don't have to create the namenprior to creating the5 The cost of the for loop has skyrocketed from 55 ms to 3,500 ms. In other words, the speed of addOne has plummeted by a factor of more than 60. This kind of overhead will wreak havoc on the performance of any software. The cost of our tracing implementation was clearly unacceptable. But eliminating the tracing mechanism altogether was not an option—we had to have some form of tracing functionality. We had to regroup and come up with a more efficient implementation. The Recovery Plan The performance recovery plan was to eliminate objects and computations whose values get dropped when tracing is off. We started with the string argument created by addOne and given to the Trace constructor. We modified the function name argument from a string object to a plain char pointer: int addOne(int x) // Version 2. Forget the string object. // Use a char pointer instead. { char *name = "addOne"; Trace t(name); return x+1; } Along with that modification, we had to modify the Trace constructor itself to take a char pointer argument instead of a string reference: inline Trace::Trace(const char *name) : theFunctionName(name)// Version 2 { if (traceIsActive) { cout << "Enter function" << name << endl; } } Similarly, the Trace::debug() method was modified as well to accept a const *char as an input argument instead of a string. Now we don't have to create the name string prior to creating the
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有