certik / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Very slow parsing on Windows 8 #248

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
What flags are you compiling with on each platform, and what are the specs of 
each machine? This looks strongly like you're using a debug build on Windows 
and an opt build on Linux.

Original comment by jbe...@gmail.com on 28 May 2014 at 1:11

GoogleCodeExporter commented 9 years ago
You're right, I didn't notice I'm using DEBUG build of library on Windows. My 
fault, sorry about that.

Original comment by obuchowi...@gmail.com on 29 May 2014 at 8:19

GoogleCodeExporter commented 9 years ago
Thanks for following up!

Original comment by jbe...@gmail.com on 29 May 2014 at 1:06