Benchmarking program to test C++ functions?

D

desktop

I have written two different insert functions in a C++ program and would
like to test the difference in performance.

Can you recommend any benchmarking software for C++ functions that can
do this job? I am working under linux/ubuntu.
 
I

Ian Collins

desktop said:
I have written two different insert functions in a C++ program and would
like to test the difference in performance.

Can you recommend any benchmarking software for C++ functions that can
do this job? I am working under linux/ubuntu.

time(1)?
 
J

Jim Langston

desktop said:
I have written two different insert functions in a C++ program and would
like to test the difference in performance.

Can you recommend any benchmarking software for C++ functions that can do
this job? I am working under linux/ubuntu.

I just use clock. such as:

clock_t Start = clock();
// Map find is so fast one search reports 0ns
for ( int i = 0; i < 1000; ++i )
FindInMap( "Bogus", "Bogus", MapData );
clock_t End = clock();
std::cout << "Search for non existant entry in Map: " <<
static_cast<double>( End - Start ) / 1000.0 << "ns\n";

You would need to include <ctime>

I am not sure if it's supposed to be std::clock or not (not using namespace
std, yet it finds it anyway in windows).
 
R

Rui Maciel

desktop said:
Can you recommend any benchmarking software for C++ functions that can
do this job? I am working under linux/ubuntu.

Take a look at cachegrind and it's KDE frontend kcachegrind. It uses
valgrind and it's readily available from the Ubuntu repositories.


Hope this helps
Rui Maciel
 
G

Gavin Deane

I just use clock. such as:

clock_t Start = clock();
// Map find is so fast one search reports 0ns
for ( int i = 0; i < 1000; ++i )
FindInMap( "Bogus", "Bogus", MapData );
clock_t End = clock();
std::cout << "Search for non existant entry in Map: " <<
static_cast<double>( End - Start ) / 1000.0 << "ns\n";

You would need to include <ctime>

I am not sure if it's supposed to be std::clock or not

Yes it is, if you get it by including <ctime>. <ctime> should not give
(not using namespace
std, yet it finds it anyway in windows).

Doesn't surprise me. A lot of popular implementations seem to get this
wrong and so formally incorrect code like yours above successfully
compiles.

I've found the problem widespread enough to not bother with <cxxx>
headers. YMMV.

Gavin Deane
 
Z

Zeppe

desktop said:
I was thinking something with a GUI interface and the option to do plots.

I don't know which plots may you be interested in, but you are probably
looking for a profiler. Check out gprof and kprof.

Regards,

Zeppe
 
J

James Kanze

I just use clock. such as:
clock_t Start = clock();
// Map find is so fast one search reports 0ns
for ( int i = 0; i < 1000; ++i )
FindInMap( "Bogus", "Bogus", MapData );
clock_t End = clock();
std::cout << "Search for non existant entry in Map: " <<
static_cast<double>( End - Start ) / 1000.0 << "ns\n";
You would need to include <ctime>
I am not sure if it's supposed to be std::clock or not (not
using namespace std, yet it finds it anyway in windows).

If you include <ctime>, it's suppose to be std::clock, and only
std::clock. If you include <time.h>, it's suppose to be both
std::clock and ::clock. To date, I've yet to see a conforming
implementation; I include <time.h> and use clock (no ::), and
that seems to work everywhere.

The problem with this solution, per se, is that you really need
something to ensure that the optimizer doesn't eliminate the
find completely. What I've used, to date, is to put the
fonction to be tested in a virtual function in a derived class,
and to ensure that it uses the results of what I'm testing to
update something in the object. This seems to have worked so
far, but one day or other, I'm sure that compilers will make it
insufficient as well.

If anyone's interested, the code is in BenchHarness, in the Test
subsystem at my site (http://kanze.james.neuf.fr/code-en.html,
when it's working).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,367
Latest member
Monarch

Latest Threads

Top