This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Sleep Less Than One Millisecond
Is there a way to "sleep" for less than a millisecond in C++, but without a busy loop?
No. Under Windows, even without sleeping you can't ensure that two consecutive instructions will be carried out with less than a millisecond between them.
Related
This question already has answers here:
How to use a timer in C++ to force input within a given time?
(5 answers)
Closed 6 years ago.
I'm writing a code where the user has to answer the question in 10 seconds or else he will lose, I know that I'm supposed to use threads but the problem is, I don't know how to do the timer, any ideas?
Thanks
You don't need threads.
Assuming time is in ms:
updateLoop(){
timeLeft = startingTime + 10.000 - now;
if (timeLeft <= 0) {
lose=true;
}
render();
}
EDIT: I probably misunderstood the question a bit. This seems to cover your question, as in #Mourad's comment:
How to use a timer in C++ to force input within a given time?
This question already has answers here:
How to determine CPU and memory consumption from inside a process
(10 answers)
Closed 7 years ago.
I have a few threads in my program - run on Windows and write in C++.
How can I know in the end of the running how much CPU time is used by all or one of them?
You can use the GetThreadTimes function: https://msdn.microsoft.com/en-us/library/windows/desktop/ms683237%28v=vs.85%29.aspx
This question already has answers here:
How to measure the inner kernel time in NVIDIA CUDA?
(2 answers)
Closed 8 years ago.
I searched a bit but all things I found could only be annotated in CPU code, how could I measure partial time inside kernel between 2 _syncthread() of 1 threadblock? Is it possible?
One approach is to use the clock() or clock64 function as described in the programming guide.
Search the cuda tag on clock64 for additional examples of its usage.
This question already has answers here:
Optimizations for pow() with const non-integer exponent?
(10 answers)
Closed 9 years ago.
I have to raise a number to the power of 1/2.2 which is 0.45454545... many times. Actually I have to do this in a loop. Simple pow/powf is very slow (when I comment out this pow from my loop code it's a loot faster). Is there any way to optimize such operation?
You might give a look at: Optimized Approximative pow() in C / C++
It also includes a benchmark.
This question already has answers here:
Why is reading lines from stdin much slower in C++ than Python?
(10 answers)
Accessing individual characters in a file inefficient? (C++)
(3 answers)
Closed 9 years ago.
I've made some programs and saw that scanf and printf are considerably faster than using cin and cout? Most of my programs clear the execution time limit, mostly 3 seconds or 5 seconds, on online compilers when using scanf/printf which exceeded the limit while using cin/cout.