Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the CLion debugger/console to tell me how many seconds my program took to run?

Tags:

c

timing

clion

How do I time my C program in Clion? Is there an option I can use to to tell me how long long my program took to run?

something like

> finished in .003 seconds

here is what I am referring to when I say debugger/console: enter image description here


like image 506
Conor Cosnett Avatar asked Aug 27 '16 13:08

Conor Cosnett


People also ask

How do you check your run time in CLion?

Run CPU Profiler You can open the report by clicking the Profiler panel on the bottom left corner. In the Flame Chart tab, you can see a visual representation of the execution time.

How do you use CLion debugger?

For debug press Shift+F9 . To help you inspect the state of your code during debugging, CLion equips you with many useful shortcuts like Step over/into ( F8/F7 ), Step out ( Shift+F8 ), or Run to cursor ( Alt+F9 ).

Does CLion use GDB?

CLion supports debugging C/C++ executables with GDB (either bundled or custom) on all platforms and with the bundled LLDB on macOS and Linux. Also, there is an LLDB-based debugger for the MSVC toolchain on Windows.

How do you set a breakpoint in CLion?

Set line breakpointsClick the gutter at the executable line of code where you want to set the breakpoint. Alternatively, place the caret at the line and press Ctrl+F8 . While in disassembly view, you can set breakpoints the same way you do in the source code.


1 Answers

You can measure the time of your code from inside your C program.

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int main() {
    clock_t start = clock();

    int n = 100; 
    int i=0;
    while(i<100*n)
        i++;

    clock_t stop = clock();
    double elapsed = (double) (stop - start) / CLOCKS_PER_SEC;
    printf("\nTime elapsed: %.5f\n", elapsed);
    return 0;
}
like image 72
Niklas Rosencrantz Avatar answered Sep 19 '22 15:09

Niklas Rosencrantz