9951 explained code solutions for 126 technologies


cHow to get the execution time of functions


#include <time.h>
clock_t tic, toc; tic = clock(); /*Some code*/ toc = clock();ctrl + c
clock_t

variable to get the clock time

clock()

function that gets the clock time


Usage example

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
    clock_t tic, toc;
    tic = clock();
    sleep(2);
    toc = clock();
    printf("sec %lu usec %lu", (unsigned long)(toc-tic) / CLOCKS_PER_SEC, (unsigned long)(toc-tic) % 1000000);
    return 0;
}
output
2 78

Alternatives