0

Hi,

i have created a program in c++ that implements dijkstra's algorithm, and i would like to count how many operations the program makes, but i dont know how.

Here is my main code:
int main()
{
int counter =0;
dij d;

d.read();

d.algorithm();

d.output();

return 0;
}

can anyone help please?
thank you in advance

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by StuXYZ
0

You have two options.
The obvious on is to add a counter to the class. This can be done several ways and then each method and submethod adds to the count.

The other (less common and normally less elegant) is to have each method return the number of operations it took. But in this case since you will have private methods etc. I think it will be easier to do option one.

You can even get a bit of object-orientated about it. You can have a derived class that is dij_with_counting, and use a virtual addOperation() , that is a no-op in the base class but does the counting in the derived class. But it is unlikely to be required or worth the effort, unless the code is going into a ibrary.
method that is a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.