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:
raven::set::cRunWatch::Start();
Notes:
* 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:
raven::set::cRunWatch runwatch("<unique name of scope>");
Notes:
* 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:
raven::set::cRunWatch::Report();
Notes:
* 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 runwatch("highly_optimised_subroutine");
Sleep( 2 );
}
void badly_written_function()
{
raven::set::cRunWatch runwatch("badly_written_function");
for (int k = 1; k < 1000; k++ )
{
highly_optimised_subroutine();
}
}
void well_written_function()
{
raven::set::cRunWatch runwatch("well_written_function");
for (int k = 1; k < 10; k++ )
{
highly_optimised_subroutine();
}
}
int _tmain(int argc, _TCHAR* argv[])
{
raven::set::cRunWatch::Start();
well_written_function();
badly_written_function();
raven::set::cRunWatch::Report();
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
You can obtain raven::Set::cRunWatch from here.
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.
Added option to write results to a file.
Added test project
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 ; )
I am glad you find the profiler useful. To profile a section of code, surround the code section with curly brackets. Immediately after the open curly brackets, write raven::set::cRunWatch runwatch(“section_name”);
Oh that’s good idea! I couldn’t think of it. Thanks!