Skip to content

Instantly share code, notes, and snippets.

@yorickdewid
Created April 20, 2015 11:28
Show Gist options
  • Select an option

  • Save yorickdewid/4102dee751e9c064296a to your computer and use it in GitHub Desktop.

Select an option

Save yorickdewid/4102dee751e9c064296a to your computer and use it in GitHub Desktop.
Puts() vs printf()
/*
* puts vs printf test
*
*/
#include <stdio.h>
#include <time.h>
#define LOOP 100000
int main(int argc, char *argv[]) {
int i;
clock_t t1, t2;
double tdiff_puts, tdiff_printf;
t1 = clock();
for(i=0; i<LOOP; ++i)
puts("Hello World");
t2 = clock();
tdiff_puts = (double)(t2-t1) / CLOCKS_PER_SEC;
t1 = clock();
for(i=0; i<LOOP; ++i)
printf("Hello World\n");
t2 = clock();
tdiff_printf = (double)(t2-t1) / CLOCKS_PER_SEC;
printf("CPU Time puts: %f\n", tdiff_puts);
printf("CPU Time printf: %f\n", tdiff_printf);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment