Very slow parsing on Windows 8
Closed this issue · 0 comments
GoogleCodeExporter commented
I've created program for measuring time of loading yaml from file:
#include <fstream>
#include <iostream>
#include <ctime>
#include <yaml-cpp/yaml.h>
using namespace std;
#pragma comment(lib, "yaml-cpp.lib")
const char *filename = "tst.yaml";
struct Timer {
clock_t start;
const char *what;
Timer(const char *what)
: start(clock()), what(what) {}
~Timer() {
}
void stop() {
auto stop = clock();
cout << what << " : " << (double)(stop - start) / (double)CLOCKS_PER_SEC << endl;
}
};
void emitYaml(YAML::Emitter &out, int level) {
out << YAML::BeginMap;
for (int i = 0; i < 20; ++i) {
out << YAML::Key << i;
out << YAML::Value;
if (level) emitYaml(out, level - 1);
else out << i;
}
out << YAML::EndMap;
}
void emitYaml(const char *filename) {
YAML::Emitter out;
emitYaml(out, 2);
ofstream fout(filename);
fout << out.c_str() << endl;
}
char data[1234567];
int main(int argc, char *argv[])
{
emitYaml(filename);
{
for (int i = 0; i < 5; ++i) {
{
Timer tmr("reading file");
ifstream input(filename);
input.read(data, 1234567);
tmr.stop();
}
{
Timer tmr("loading");
YAML::Load(data);
tmr.stop();
}
}
}
cout << "---------------" << endl;
{
YAML::Node node;
for (int i = 0; i < 5; ++i) {
{
Timer tmr("reading file");
ifstream input(filename);
input.read(data, 1234567);
tmr.stop();
}
{
Timer tmr("loading");
node = YAML::Load(data);
tmr.stop();
}
}
}
return 0;
}
Output on Funtoo Linux:
reading file : 0
loading : 0.22
reading file : 0.01
loading : 0.23
reading file : 0
loading : 0.23
reading file : 0
loading : 0.23
reading file : 0
loading : 0.23
---------------
reading file : 0
loading : 0.22
reading file : 0
loading : 0.22
reading file : 0
loading : 0.22
reading file : 0.01
loading : 0.22
reading file : 0
loading : 0.22
Output on Windows 8:
reading file : 0
loading : 6.332
reading file : 0
loading : 7.959
reading file : 0
loading : 6.567
reading file : 0
loading : 6.377
reading file : 0.01
loading : 6.347
---------------
reading file : 0
loading : 6.037
reading file : 0
loading : 6.177
reading file : 0
loading : 6.397
reading file : 0
loading : 5.836
reading file : 0
loading : 5.847
Original issue reported on code.google.com by obuchowi...@gmail.com
on 28 May 2014 at 1:05