// Demonstrate the speed improvement from using stdio vs raw syscalls #include #include #include #include #include #include const int N_COPIES = 10; void dumpstdio(const char* string) { // Open the file FILE* fp = fopen("dump.txt", "w+"); int len = strlen(string); for(int i = 0; i < N_COPIES; i++){ // Write the string fwrite(string, len, 1, fp); } // Close the file fclose(fp); } void dumpsyscall(const char* string) { // Open the file int fp = open("dump.txt", O_WRONLY | O_CREAT); int len = strlen(string); for(int i = 0; i < N_COPIES; i++){ // Write the string write(fp, string, len); } // Close the file close(fp); } int main(int argc, char* argv[]) { dumpstdio(argv[1]); //dumpsyscall(argv[1]); return(0); }