can someone please show me a simple for loop that is so slow (exponential?) it takes a minute to run?
can someone please show me a simple for loop that is so slow (exponential?) it takes a minute to run?
Code:for (;;) { }
1. create a function that increments a static variable or otherwise does some work that can be discarded
2. make a nested loop with multiple levels where the inner loop calls the function . start with two loops, one inside the other
3. tune the loop counts until it runs as long as you want. start with INNER = 1 and OUTER = something kind of big, like 1000000
4. run it. double the value of OUTER until it runs 10 seconds
5. change INNER to 6
6. if you can't get it to run 10 seconds with INNER = 1, double INNER and start over with OUTER
What rolls down stairs alone or in pairs
Rolls over your neighbor's dog?
What's great for a snack and fits on your back?
It's Log, Log, Log!
Well, a loop from 1 to 60 which consisted of entirely a Sleep for 1 second would do it.
You're going to have to do better at asking questions to get what you are really after!
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
A minute running on what kind of hardware? Ever try to play an old DOS game on new hardware and find that timing events happen ridiculously fast, because they were written for a 25 MHz processor?
Of course, the better question isn't how to do this - it's why WOULD you do this? Sleep functions have been standard for decades, and pre-emptively multitasking operating systems are going to strongly encourage you to use them, so that other processes and threads can run on the core that you would otherwise be monopolizing. MacGuyvering your own poor substitute for sleep() isn't just unnecessary, it's not going to work as well.
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.