Is there a significant difference in speed when scaling the following two program structures:
map<string, std::function<string()>> myMap = {
{"hello", [](){ return " world"; }}
};
int main()
{
cout << "hello" << myMap["hello"]();
return 0;
}
vs.
int main()
{
map<string, std::function<string()>> myMap;
myMap["hello"] = [](){ return " world"; };
cout << "hello" << myMap["hello"]();
return 0;
}
One part of me wants to think that the globally initialized myMap will be faster, but since map is part of stl, that makes me think it's impossible for the actual map to be populated until runtime, since it uses dynamic memory allocation internally (unlike a globally initialized int array, which is baked into the executable, for example). Am I correct in thinking these two methods are virtually identical as far as reducing the amount of time to look-up something in a map?
Aucun commentaire:
Enregistrer un commentaire