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,884 questions

51,810 answers

573 users

How to measure function execution time in C

1 Answer

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

void f() { 
    int i = 0;
    
    while(i < 100000) { 
        i++;
    } 
} 

int main() 
{ 
    clock_t ct = clock(); 
    
    f(); 
    ct = clock() - ct; 
    double total_time = ((double)ct) / CLOCKS_PER_SEC; 
  
    printf("%f seconds", total_time);
    
    return 0; 
} 


/*
run:

0.000258 seconds

*/

 



answered Apr 5, 2019 by avibootz

Related questions

2 answers 137 views
1 answer 123 views
123 views asked May 29, 2023 by avibootz
1 answer 226 views
4 answers 284 views
2 answers 130 views
1 answer 116 views
1 answer 215 views
...