Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

How to get the CPU time spent on a code block in C

1 Answer

0 votes
#include <stdio.h>
#include <time.h>

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

    for (int i = 0; i < 30000000; i++) {}

    clock_t end_t = clock();

    double total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
    
    printf("Total CPU time = %f seconds", total_t);

    return 0;
}




/*
run:

Total CPU time = 0.039000 seconds

*/

 



answered Jan 8, 2023 by avibootz

Related questions

1 answer 85 views
1 answer 292 views
2 answers 137 views
2 answers 255 views
1 answer 204 views
204 views asked Jul 28, 2017 by avibootz
...