Loading ifs_test/main.cpp +36 −33 Original line number Diff line number Diff line Loading @@ -2,48 +2,32 @@ #include <unistd.h> #include <fstream> #include <fcntl.h> #include <sys/stat.h> #include <chrono> using namespace std; int main() { using ns = chrono::nanoseconds; using get_time = chrono::steady_clock; // std::fstream fs; // fs.open("testcpp_open.txt", std::fstream::in | std::fstream::out | std::fstream::app); // // fs << "lorem ipsum"; // fs.close(); // ofstream ofs("/tmp/test_ofstream"); // // ofs << "lorem upsum"; // ofs.close(); // // auto buf = "BUFFERINO2"; // auto fd2 = open("/tmp/test_open.txt", O_WRONLY|O_CREAT|O_TRUNC,0666); // write(fd2, buf, 9); // cout << close(fd2) << endl; // auto fd3 = fopen("test_fopen", "w"); // fputs(buf, fd3); // fclose(fd3); int main() { // for (int i = 0; i < 200; ++i) { // printf("%d\n", i); // auto fd = open("test2.txt", O_WRONLY); // write(fd, buf, 9); // close(fd); // sleep(1); // } auto buf = "BUFFERINO2"; // cout << mkdir("/tmp/mountdir/bla", 0775) << endl; // auto buf = "BUFFERINO2"; // struct stat attr; // cout << creat("/tmp/mountdir/creat.txt", 0666) << endl; // cout << creat("/tmp/mountdir/#test-dir.0/mdtest_tree.0/file.mdtest.0000000.0000000005", 0666) << endl; // cout << stat("/tmp/mountdir/creat.txt", &attr) << endl; // cout << unlink("/tmp/mountdir/creat.txt") << endl; // auto pid = fork(); // if (pid == 0) { auto fd2 = open("/tmp/child_open.txt", O_WRONLY|O_CREAT|O_TRUNC,0666); write(fd2, buf, 9); cout << close(fd2) << endl; // auto fd2 = open("/tmp/child_open.txt", O_WRONLY|O_CREAT|O_TRUNC,0666); // write(fd2, buf, 9); // cout << close(fd2) << endl; // } else if (pid > 0) { // auto fd3 = open("/tmp/parent_open.txt", O_WRONLY|O_CREAT|O_TRUNC,0666); // write(fd3, buf, 9); Loading @@ -53,11 +37,30 @@ int main() { // return 1; // } int filen = 3; auto start_t = get_time::now(); for (int i = 0; i < filen; ++i) { string p = "/tmp/mountdir/file2" + to_string(i); creat(p.c_str(), 0666); if (i % 25000 == 0) cout << i << " files processed.2" << endl; // cout << p << endl; } auto end_t = get_time::now(); auto diff = end_t - start_t; auto diff_count = chrono::duration_cast<ns>(diff).count(); cout << diff_count << "ns\t" << (diff_count) / 1000000. << "ms" << endl; cout << filen / ((diff_count) / 1000000000.) << " files per second" << endl; cout << "done" << endl; // cout << "done" << endl; return 0; } No newline at end of file Loading
ifs_test/main.cpp +36 −33 Original line number Diff line number Diff line Loading @@ -2,48 +2,32 @@ #include <unistd.h> #include <fstream> #include <fcntl.h> #include <sys/stat.h> #include <chrono> using namespace std; int main() { using ns = chrono::nanoseconds; using get_time = chrono::steady_clock; // std::fstream fs; // fs.open("testcpp_open.txt", std::fstream::in | std::fstream::out | std::fstream::app); // // fs << "lorem ipsum"; // fs.close(); // ofstream ofs("/tmp/test_ofstream"); // // ofs << "lorem upsum"; // ofs.close(); // // auto buf = "BUFFERINO2"; // auto fd2 = open("/tmp/test_open.txt", O_WRONLY|O_CREAT|O_TRUNC,0666); // write(fd2, buf, 9); // cout << close(fd2) << endl; // auto fd3 = fopen("test_fopen", "w"); // fputs(buf, fd3); // fclose(fd3); int main() { // for (int i = 0; i < 200; ++i) { // printf("%d\n", i); // auto fd = open("test2.txt", O_WRONLY); // write(fd, buf, 9); // close(fd); // sleep(1); // } auto buf = "BUFFERINO2"; // cout << mkdir("/tmp/mountdir/bla", 0775) << endl; // auto buf = "BUFFERINO2"; // struct stat attr; // cout << creat("/tmp/mountdir/creat.txt", 0666) << endl; // cout << creat("/tmp/mountdir/#test-dir.0/mdtest_tree.0/file.mdtest.0000000.0000000005", 0666) << endl; // cout << stat("/tmp/mountdir/creat.txt", &attr) << endl; // cout << unlink("/tmp/mountdir/creat.txt") << endl; // auto pid = fork(); // if (pid == 0) { auto fd2 = open("/tmp/child_open.txt", O_WRONLY|O_CREAT|O_TRUNC,0666); write(fd2, buf, 9); cout << close(fd2) << endl; // auto fd2 = open("/tmp/child_open.txt", O_WRONLY|O_CREAT|O_TRUNC,0666); // write(fd2, buf, 9); // cout << close(fd2) << endl; // } else if (pid > 0) { // auto fd3 = open("/tmp/parent_open.txt", O_WRONLY|O_CREAT|O_TRUNC,0666); // write(fd3, buf, 9); Loading @@ -53,11 +37,30 @@ int main() { // return 1; // } int filen = 3; auto start_t = get_time::now(); for (int i = 0; i < filen; ++i) { string p = "/tmp/mountdir/file2" + to_string(i); creat(p.c_str(), 0666); if (i % 25000 == 0) cout << i << " files processed.2" << endl; // cout << p << endl; } auto end_t = get_time::now(); auto diff = end_t - start_t; auto diff_count = chrono::duration_cast<ns>(diff).count(); cout << diff_count << "ns\t" << (diff_count) / 1000000. << "ms" << endl; cout << filen / ((diff_count) / 1000000000.) << " files per second" << endl; cout << "done" << endl; // cout << "done" << endl; return 0; } No newline at end of file