Measure execution time in C (for Linux and Windows)

  Рет қаралды 9,974

CodeVault

CodeVault

Жыл бұрын

Links related to the topic of measuring execution time:
stackoverflow.com/a/37920181
learn.microsoft.com/en-us/win...
Source code can be found here:
code-vault.net/lesson/7475a60...
===== Support us through our store =====
code-vault.net/shop
===== Check out our website =====
code-vault.net
===== Check out our Discord server =====
discord.code-vault.net

Пікірлер: 21
@KFlorent13
@KFlorent13 Жыл бұрын
Oh you are back ! How exciting ;)
@isaiasramirez2909
@isaiasramirez2909 Жыл бұрын
great video!
@NenieIri
@NenieIri Жыл бұрын
and what are you think about clock() function? In manual says "clock - determine processor time". Does it correct to use for measurement or not?
@CodeVault
@CodeVault Жыл бұрын
On Linux, it's a good choice since it simply calls clock_gettime with the CPUTIME constant. On Windows it returns the wall clock and recommends us using what I showed in the video (learn.microsoft.com/en-us/cpp/c-runtime-library/reference/clock?view=msvc-170). Not sure about other platforms. I found it in my research and decided to not show it as it causes more confusion.
@NenieIri
@NenieIri Жыл бұрын
@@CodeVault Thank you
@mehregankbi
@mehregankbi Жыл бұрын
now i don't know if it's the best way of doing this, but measuring the difference between a process' cpu time and wall time could be used to measure io boundedness of that process. (given that the CPU is not overloaded, so the amount of time the process spends in the ready queue is negligible compared to the amount of time that it stays in the waiting queue.
@CodeVault
@CodeVault Жыл бұрын
That's a nice topic to research about. There are many instances where processes are slow due to IO operations and finding that out is quite useful. I might even make a video on this
@michaelvanzyl9418
@michaelvanzyl9418 Жыл бұрын
Would the compiler not be clever enough to optimise out any operations done on x, if it’s never read from? (Or does that require an optimisation flag)
@CodeVault
@CodeVault Жыл бұрын
Yes, it does optimize it away but only with -O2. By default it should be left alone
@michaelvanzyl9418
@michaelvanzyl9418 Жыл бұрын
@@CodeVault ahh, makes sense.
@markobrodanac4304
@markobrodanac4304 Жыл бұрын
Is this CPU time equal to sys or user time when measuring with time function in shell?
@CodeVault
@CodeVault Жыл бұрын
In shell the time command is explained here: linux.die.net/man/1/time You do get real time and CPU user time
@mritunjaykumar8332
@mritunjaykumar8332 Жыл бұрын
can you please create a video on EPOCH time, how to convert epoch time (in seconds) to actual time without using any inbuilt functions in c ?
@CodeVault
@CodeVault Жыл бұрын
There is this video on the topic: code-vault.net/lesson/931c1634bae351f1ec660773c5001a5b Although it does use some standard functions. I noted down your question, maybe I will do a video on that if it's not too difficult (working with date and time is often complicated)
@mritunjaykumar8332
@mritunjaykumar8332 Жыл бұрын
@@CodeVault Thank you for your awesome videos
@msrinivas20
@msrinivas20 Жыл бұрын
Where can I get this compiler sir ? How can I install it. Please reply back the link. Tq
@CodeVault
@CodeVault Жыл бұрын
gcc gcc.gnu.org/ can be found on most Linux distros and, for Windows I am just using MSVC in Visual Studio visualstudio.microsoft.com/
@akhilpandey1539
@akhilpandey1539 Жыл бұрын
My question is different from this topic... Can we find the maximum number of thread that we can create in a program?
@CodeVault
@CodeVault Жыл бұрын
To find out you can simply use this command: cat /proc/sys/kernel/threads-max
@mba2ceo
@mba2ceo 4 ай бұрын
||=== Build: Debug in timeckick (compiler: GNU GCC Compiler) ===| C:\zzz-code\options\timeckick\main.cpp||In function 'int main(int, char**)':| C:\zzz-code\options\timeckick\main.cpp|8|error: aggregate 'main(int, char**)::timespec begin' has incomplete type and cannot be defined| C:\zzz-code\options\timeckick\main.cpp|9|error: 'TIME_UTC' was not declared in this scope| C:\zzz-code\options\timeckick\main.cpp|9|error: 'timespec_get' was not declared in this scope| C:\zzz-code\options\timeckick\main.cpp|22|error: aggregate 'main(int, char**)::timespec end' has incomplete type and cannot be defined| ||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
@CodeVault
@CodeVault 3 ай бұрын
Try using the code for Windows instead. You can find it here under main-vs.c: code-vault.net/lesson/7475a60f972f545c64ae6e5ab80007af
What are variadic functions (va_list) in C?
13:49
CodeVault
Рет қаралды 20 М.
why do void* pointers even exist?
8:17
Low Level Learning
Рет қаралды 338 М.
Gym belt !! 😂😂  @kauermtt
00:10
Tibo InShape
Рет қаралды 10 МЛН
Дарю Самокат Скейтеру !
00:42
Vlad Samokatchik
Рет қаралды 8 МЛН
HAPPY BIRTHDAY @mozabrick 🎉 #cat #funny
00:36
SOFIADELMONSTRO
Рет қаралды 17 МЛН
路飞被小孩吓到了#海贼王#路飞
00:41
路飞与唐舞桐
Рет қаралды 79 МЛН
Why C is so Influential - Computerphile
10:50
Computerphile
Рет қаралды 1,9 МЛН
Difference between processes and threads
10:30
CodeVault
Рет қаралды 108 М.
Why Function Pointers are Awesome
11:11
Jacob Beningo
Рет қаралды 5 М.
How to measure memory usage inside my program? (getrusage)
13:08
Jacob Sorber
Рет қаралды 30 М.
Making Minimalist Web Server in C on Linux
10:23
Nir Lichtman
Рет қаралды 235 М.
Mastering Memory: Allocation Techniques in C, C++, and ARM Assembly
17:05
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 289 М.
Communicating between processes (using pipes) in C
14:00
CodeVault
Рет қаралды 270 М.
STOP Learning These Programming Languages (for Beginners)
5:25
Andy Sterkowitz
Рет қаралды 667 М.
Gym belt !! 😂😂  @kauermtt
00:10
Tibo InShape
Рет қаралды 10 МЛН