🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Question about a question.

Started by
0 comments, last by Wolfdog 16 years, 9 months ago
Sorry for the confusing heading. The situation is this: I have a question that I cannot understand fully. I have a delay(x) function that does some meaningless yet complex stuff in its body (a loop that iterates x times) . In the main function, I take down the duration of running delay(x) via using gettimeofday(). With this program, I am supposed to answer this following question: The delay(x) function delays for a time approximately proportional to the value of x. Find out how long the delay(x) function takes for x. For example, if it takes y microseconds for each x (?) , then delay(z) should take about zy microseconds. What is the value of y? Am I suppose to find the value of the pre-emptive time given to each process as y? But I have results that are pretty small in the beginning. delay(1) gives me 5 uS while delay(2) gives me 6. That should be 10. So y is not the preemptive time. My question is: What is x,y,z? I cannot fully comprehend the question at all. I am running this program on Fedora 7. Compilation via gcc. The code is here: #include <stdio.h> #include <stdlib.h> double delay(unsigned long loops) { unsigned long i; double z = i, y; z = i; for ( i = loops; i>=1;i-- ) { y = loops/(loops-i+1); z= (y*y+z) * i / loops; } return z; } int main(int argc, char* argv[] ) { struct timeval before, after; int i, n; if ( argc == 2 ) n = atoi(argv[1]); else exit(0); //capture the time gettimeofday(&before); delay(n); //capture the time again gettimeofday(&after); //get the time difference int duration = (after.seconds - before.seconds) *1000000 + ( after.useconds - before.useconds ); //print out the result blah! }
Advertisement
Sorry buddy,

Gamedev has a very strict policy on homework questions. Not only are you not allowed to post it, but we are not allowed to answer. You should consult the person(s) whom gave you the question.

This topic is closed to new replies.

Advertisement