[Assorted-commits] SF.net SVN: assorted:[1411] sandbox/trunk/src/cc/sync.cc
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-05-13 16:55:18
|
Revision: 1411 http://assorted.svn.sourceforge.net/assorted/?rev=1411&view=rev Author: yangzhang Date: 2009-05-13 16:55:10 +0000 (Wed, 13 May 2009) Log Message: ----------- added file sync demo Added Paths: ----------- sandbox/trunk/src/cc/sync.cc Added: sandbox/trunk/src/cc/sync.cc =================================================================== --- sandbox/trunk/src/cc/sync.cc (rev 0) +++ sandbox/trunk/src/cc/sync.cc 2009-05-13 16:55:10 UTC (rev 1411) @@ -0,0 +1,58 @@ +#include <unistd.h> +#include <fstream> +#include <commons/time.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +using namespace commons; +using namespace std; +enum { sz = 4096 }; + +int main() { + char str[sz]; + int fd = creat("/tmp/out", 0644); + + { + long long start = current_time_millis(); + int i; + for (i = 0; (i & 0xf) != 0xf || current_time_millis() - start < 1000; ++i) { + write(fd, str, sz); + } + long long end = current_time_millis(); + cout << i << ' ' << end - start << endl; + fdatasync(fd); + } + + { + long long start = current_time_millis(); + int i; + for (i = 0; (i & 0xf) != 0xf || current_time_millis() - start < 1000; ++i) { + write(fd, str, sz); + fdatasync(fd); + } + long long end = current_time_millis(); + cout << i << ' ' << end - start << endl; + } + + { + long long start = current_time_millis(); + int i; + for (i = 0; (i & 0xf) != 0xf || current_time_millis() - start < 1000; ++i) { + write(fd, str, sz); + long long s = current_time_millis(); + fdatasync(fd); + cout << current_time_millis() - s << endl; + } + long long end = current_time_millis(); + cout << i << ' ' << end - start << endl; + } + +#if 0 + // Can't get the fd of an fstream. + ofstream of("/tmp/out"); + of.write(str, sz); +#endif + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |