2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by corby
1

call clock() before the loop starts and again after the loop ends, then subtract the two times. When the program runs fast enough the difference might be 0. In that case, put the loops into a function and call that function 1,000 times.

clock_t t1, t2;
t1 = clock();
for(int i = 0; i < 1000; i++)
     RunLoops();
t2 = clock();
clock_t diff = t2 - t1;
0

call clock() before the loop starts and again after the loop ends, then subtract the two times. When the program runs fast enough the difference might be 0. In that case, put the loops into a function and call that function 1,000 times.

clock_t t1, t2;
t1 = clock();
for(int i = 0; i < 1000; i++)
     RunLoops();
t2 = clock();
clock_t diff = t2 - t1;

my professor just wants us to find the time in terms of the big O by using like T(n) or whatever im just confused on how to find it in those terms. im sorry i should've been more specific

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.