# Question about a question.

This topic is 4037 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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! }

##### Share on other sites
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.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 72
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632967
• Total Posts
3009576
• ### Who's Online (See full list)

There are no registered users currently online

×