Skip to content

Instantly share code, notes, and snippets.

Created August 16, 2014 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3ef573533ac87d68d031 to your computer and use it in GitHub Desktop.
Save anonymous/3ef573533ac87d68d031 to your computer and use it in GitHub Desktop.
#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