View mode: basic / threaded / horizontal-split · Log in · Help
April 18, 2008
Question to std.perf users
Is anyone using std.perf's scoped counter?

As in

   scope timer = new PerformanceCounterScope!(PerformanceCounter);
   // [..do stuff..]
   timer.stop();
   auto msec = timer.milliseconds();

or it could take the form

   scope timer = new PerformanceCounter.scope_type;
   // ... same as above


Basically all it does is automatically call "start()" for you.
Seems like a waste to me.  Calling start() isn't that hard, and is clearer.

The article by Matthew Wilson referenced in the documentation even says 
it's not very useful:
"""
However, the observed use of these classes — in almost all cases — along 
with the strong requirement for them to be as efficient as possible, has 
shown this to be a mistake. Because instances are often used in a number 
of start()-stop() cycles, as can be seen in the test program, having 
start() called in the constructor complicates the semantics for no net 
benefit.
"""
 --- http://www.ddj.com/windows/184416651


So I say it should just be ripped out.
Unless someone things it's really great and uses it all the time.

--bb
Top | Discussion index | About this forum | D home