Created
March 13, 2013 11:35
-
-
Save dobrokot/5151284 to your computer and use it in GitHub Desktop.
Testing speed of ofstream and FILE*
This file contains 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
#include <iostream> | |
#include <fstream> | |
#include <stdio.h> | |
const int N = 1000*1000*10; | |
void f1() { | |
std::ofstream out("out.txt", std::ios::binary); | |
for (int i = 0; i < N; ++i) { | |
out << i << ' ' << i << ' ' << i << '\n'; | |
} | |
} | |
void f2() { | |
FILE *out = fopen("out.txt", "wb"); | |
for (int i = 0; i < N; ++i) { | |
fprintf(out, "%d %d %d\n", i, i, i); | |
} | |
fclose(out); | |
} | |
int main(int argc, char **argv) { | |
if (argc < 2) { | |
fprintf(stderr, "invalid parameters"); | |
return 1; | |
} | |
if (argv[1][0] == '1') | |
f1(); | |
else if (argv[1][0] == '2') | |
f2(); | |
else { | |
fprintf(stderr, "invalid parameters"); | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment