Fast, Safe, Custom Software Engineering – Raven’s Point is focused on engineering software that delivers your solutions before you expect and with the greatest reliability.

This the Raven’s Point mission statement. What does it mean? Partly it means that I specialize in delivering more quickly than the competition individually designed and coded software that is carefully tested and documented.

It also means that the programs I deliver run extremely fast, making the best use of optimizing compilers and high speed multi-core hardware.

I enjoy re-arranging computer code so that it goes faster.

Re-arranging code is dangerous. It is very easy to break something that was previously working. An effective test framework and a good set of regression tests are vital to prevent one step forward causing ten steps backward. No-one needs the wrong results reached ten times faster.

Re-arranging code is also seductive. Even if you do not do any harm, you can spend a lot of time achieving nothing. It usually turns out that a program spends most of its time executing a very few lines of code, but it can be very difficult to guess which lines these are going to be. Before optimizing, it is necessary to measure carefully and find exactly where the bottleneck is that will repay being optimized.

::raven::set::cRunWatch is a code timing profiler which can tell exactly how long a program spends executing every piece of code.

It is just two files, so it is easy to integrate with your projects, and requires adding exactly one line to instrument a piece of code.

To start profiling:


*  This can be done anywhere, but usually early in the main function.
*  This can be called without creating an instance of the profiler.
*  If not called, all cRunWatch methods become no-ops
*  If called with a zero parameter, all cRunWatch methods become no-ops.

To profile a code scope, construct a cRunWatch object which will exist for exactly as long as the scope:

raven::set::cRunWatch aWatcher("<unique name of scope>");

*  This should be done as the first line of the scope.
*  The scope is usually a function, but can be any pair of curly braces {}

To write a report to standard output:


*  This can be done anywhere, but usually at the end of the main function.
*  This can be called without creating an instance of the profiler.

Example of Use

void highly_optimised_subroutine()
raven::set::cRunWatch aWatcher("highly_optimised_subroutine");
Sleep( 2 );

void badly_written_function()
raven::set::cRunWatch aWatcher("badly_written_function");
for (int k = 1; k < 1000; k++ )

void well_written_function()
raven::set::cRunWatch aWatcher("well_written_function");
for (int k = 1; k < 10; k++ )

int _tmain(int argc, _TCHAR* argv[])



return 0;

Report produced:

raven::set::cRunWatch code timing profile
Scope                          Calls   Mean (secs)           Total
highly_optimised_subroutine     1008      0.002923        2.946213
badly_written_function             1      2.926662        2.926662
well_written_function              1      0.026161        0.026161

The Daisy Chain Feature

The default configuration combines all calls to a scope into one tally.  If you prefer to see the time spend running a scope broken out depending on which calling path invoked the scope, then start profiling using the Daisy Chain feature


which produces output like this

raven::set::cRunWatch code timing profile
 Calls           Mean (secs)     Total           Scope
        1        0.001980        0.001980        main/
        1        0.001256        0.001256        main/func1/
        1        0.000505        0.000505        main/func1/func2/
        1        0.000365        0.000365        main/func1/func2/func3/
        1        0.000283        0.000283        main/func3/
        1        0.000151        0.000151        main/func3/func4/
        1        0.000005        0.000005        main/func3/func4/func5/

Note that, for a scope to appear in the list ( daisy chain ) of scopes that call a watched scope , you must have constructed a watcher for both scopes.

The feature and the method to implement it was suggested by Moshe Rubin.

Source Code

You can obtain raven::Set::cRunWatch from here.

About these ads
This entry was posted in Software Engineering Tool. Bookmark the permalink.

6 Responses to Timing

  1. Florian says:

    I found this intrusive profiler via stackoverflow as I was looking for a C++ profiler that was free, simple and intrusive (e.g. not relying on sampling). Automatic intrusive profiling (done by e.g. the EQATEC profiler) tends to distort results as it itself adds overhead to function calls – manually selecting environments to profile fixes this. This profiler worked pretty much out of the box as advertised and to me is definitely a good add on to a sampling based profiler. In my current setup in visual studio I have my main source code compiled as a lib in one project, and then several projects on top of this, one for unit testing, one for log output, and now also one that uses this profiler. Works well for me.

  2. ravenspoint says:

    Added option to write results to a file.
    Added test project

  3. Sanghoon Lee says:

    I found this via stackoverflow and works very well for me too. But it would be better if I could specify scope of code to profile instead of doing whole function. I did it by creating instance and deleting it since it stops timer in destructor. But I don’t want to allocate new memory dynamically in profiling time and stop timer interface would be much convenient. Thanks ; )

  4. Moshe Rubin says:

    I too found out about cRunWatch through James’s comment in StackOverflow. In the past I used Compuware’s BoundsChecker and profiling tools, but had to drop them because of problems with Windows 8.

    My interest in cRunWatch was piqued by its claim of simplicity, and I was surprised that the tool is indeed very simple and quite versatile to use. In my case I needed to profile a large proprietary core library. Every function in the library had a macro at the beginning of the function scope for enabling function tracing, so I just inserted a line into the existing macro to instantiate a raven::set::cRunWatch() object, and I had the entire library ready for profiling within minutes.

    I am amazed at the ease of using cRunWatch, and highly recommend it for any seasoned developer who wants to profile a project but doesn’t want to wade too deeply into the complexities (and the costs ) of other profiling tools. Having access to the simple source code enables one to understand exactly what is going on. You can be sure this will remain a tool in my programming tool box.

    A big thanks to James for sharing this delightful utility with the programming community.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s