Created
April 20, 2015 11:28
-
-
Save yorickdewid/4102dee751e9c064296a to your computer and use it in GitHub Desktop.
Puts() vs printf()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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