user1251302
user1251302

Reputation: 91

Running Times of Algorithms

I need to run a segment of code like shown:

 sum = 0;
 for(i = 0; i < n; i++)
     for(j = 0; j < i; j++)
         sum++;

and find the running times of several values of N and the growth rate associated with those values.

Right now I am using Dev C++ (could use any IDE), but I can't figure out a way to actually display the run times.

Upvotes: 0

Views: 66

Answers (1)

Yann Ramin
Yann Ramin

Reputation: 33197

You can:

  1. Time in the application. For instance, use the time() API: http://linux.die.net/man/2/time
  2. Time by wrapping your application in another application, that can time runtimes. On *nix systems, there is a handy utility named time.
  3. Use a stopwatch.

Upvotes: 1

Related Questions