Why is scanf/printf faster than cin/cout? [duplicate] - c++

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.

Related

How would I add or multiply extremly large numbers e.g. 20 digit number x 5 digit number...? [duplicate]

This question already has answers here:
Big numbers library in c++ [closed]
(4 answers)
Store and work with Big numbers in C
(3 answers)
Closed 2 years ago.
I'm new to c++ so I don't know if there are any specific libraries that could do this. Any help would be appreciated!

How could I know how much CPU time is used by all threads? [duplicate]

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

How do I find the L2CacheSize, L3CacheSize from C++ on Windows7? [duplicate]

This question already has answers here:
C++ cache aware programming
(10 answers)
Closed 7 years ago.
I am profiling my code on various CPUs running Windows7 and my results so far suggest that I need to tune a buffer size proportional to the machine's L2CacheSize or L3CacheSize. Is there a way to obtain these parameters from C++?
You can use the GetLogicalProcessorInformation function to get that. It returns an array of SYSTEM_LOGICAL_PROCESSOR_INFORMATION structures which contain a CACHE_DESCRIPTOR structure, which provides the cache size information.

Optimizing pow algorithm [duplicate]

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.

Sleeping for less than a millisecond in C++ [duplicate]

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.