Created
May 26, 2020 03:24
-
-
Save anuragkh/f20bd67b7a04381d23b7d3b63130e081 to your computer and use it in GitHub Desktop.
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 <cstdio> | |
#include <fstream> | |
#include <cstdlib> | |
#include <string> | |
#include <cstring> | |
#include <ctime> | |
#include <chrono> | |
using namespace std; | |
static uint64_t now_us() { | |
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now(); | |
return static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count()); | |
} | |
int main() { | |
string data(1024 * 128, 'a'); | |
char buffer[1024 * 128 * 40]; | |
int tail_ = 0; | |
fstream local; | |
local.rdbuf()->pubsetbuf(0, 0); | |
local.open("test_output", std::ios::out | std::ios::trunc | std::ios::binary); | |
for(int i = 0; i < 40; i++) { | |
auto start_time_1 = now_us(); | |
local.seekp(tail_, std::ios::beg); | |
local.write(data.c_str(), 128 * 1024); | |
local.flush(); | |
auto end_time_1 = now_us(); | |
std::memcpy(&buffer[tail_], data.c_str(), 128 * 1024); | |
auto end_time_2 = now_us(); | |
tail_ += 128 * 1024; | |
cout << "Persistent: " << " " << end_time_1 - start_time_1 << " Memory: " << end_time_2 - end_time_1 << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment