0

Just a quick question about the inner workings of yaml-cpp.

I noticed that when i tried to look up a key that didn't exist i got an error such as:

yaml-cpp: error at line 0, column 0: bad conversion

I was suprised by this because I would have assumed by this point post loading we would be operating directly off an in memory map

If i do lookup such as

string foo = myyaml["bar"]["foo"].as<string>();

Does that happen as efficiently as if I had a strongly typed map. Would it be more efficient if I preprocess the things i know to exist in the yaml into a c++ map and access them directly rather than via the node?

I guess i'm asking if the perf of a map is faster than acessing a node

Thanks

easytiger
  • 514
  • 5
  • 15

1 Answers1

1

Lookup in a map in yaml-cpp is O(n) - it loops through all entries in the map. See this issue on the project page.

Lookup in std::map is O(log n) - it stores keys in order, and binary searches to find your key. So if you have a large number of keys, it might be faster to preprocess your data. But you should probably measure first :)

Jesse Beder
  • 33,081
  • 21
  • 109
  • 146
  • Thanks I implemented both direct lookups to yaml-cpp and to c++ maps carrying the same data with no other code changes. (I simple preprocess the bits i need to look up a lot into 3 other maps). It worked out about 43% less cpu on average. It's a very nice and easy to use library by the way. :) – easytiger Jul 31 '13 at 14:53