-
-
Save anonymous/3ef573533ac87d68d031 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 <cmath> | |
#include <cstdio> | |
#include <fstream> | |
#include <iomanip> | |
#include <iostream> | |
#include <nonius/main.h++> | |
struct CRead | |
{ | |
CRead(char const* filename) : _filename(filename) {} | |
void operator()() | |
{ | |
FILE* file = fopen(_filename, "r"); | |
int count = 0; | |
while (fscanf(file, "%s", _buffer) == 1) { ++count; } | |
fclose(file); | |
} | |
char const* _filename; | |
char _buffer[1024]; | |
}; | |
NONIUS_BENCHMARK("C", [](nonius::chronometer meter) | |
{ | |
std::vector<nonius::storage_for<std::string>> storage(meter.runs()); | |
meter.measure([&](int i) { storage[i].construct("small"); }); | |
}) | |
struct CppRead | |
{ | |
CppRead(char const* filename) : _filename(filename), _buffer() {} | |
enum { BufferSize = 16184 }; | |
void operator()() | |
{ | |
std::ifstream file(_filename, std::ifstream::in); | |
// comment to remove extended buffer | |
file.rdbuf()->pubsetbuf(_buffer, BufferSize); | |
int count = 0; | |
std::string s; | |
while (file >> s) { ++count; } | |
} | |
char const* _filename; | |
char _buffer[BufferSize]; | |
}; | |
NONIUS_BENCHMARK("C++", [](nonius::chronometer meter) | |
{ | |
std::vector<nonius::storage_for<std::string>> storage(meter.runs()); | |
meter.measure([&](int i) { storage[i].construct("small"); }); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment