Advertisement
Guest User

Untitled

a guest
May 29th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. /*
  2. * puts vs printf test
  3. *
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <time.h>
  8.  
  9. #define LOOP 100000
  10.  
  11. int main(int argc, char *argv[]) {
  12. int i;
  13. clock_t t1, t2;
  14. double tdiff_puts, tdiff_printf;
  15.  
  16. t1 = clock();
  17. for(i=0; i<LOOP; ++i)
  18. puts("Hello World");
  19. t2 = clock();
  20. tdiff_puts = (double)(t2-t1) / CLOCKS_PER_SEC;
  21.  
  22. t1 = clock();
  23. for(i=0; i<LOOP; ++i)
  24. printf("Hello World\n");
  25. t2 = clock();
  26. tdiff_printf = (double)(t2-t1) / CLOCKS_PER_SEC;
  27.  
  28. printf("CPU Time puts: %f\n", tdiff_puts);
  29. printf("CPU Time printf: %f\n", tdiff_printf);
  30.  
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement