//
// main.cpp
// test_map
//
// Created by Sergey on 10.09.14.
// Copyright (c) 2014 Sergey Perepelitsa. All rights reserved.
//
#include <iostream>
#include <map>
#include <unordered_map>
#include <chrono>
enum class StringEnum
{
stringparam00,
stringparam01,
stringparam02,
stringparam03,
stringparam04,
stringparam05,
stringparam06,
stringparam07,
stringparam08,
stringparam09,
stringparam10,
stringparam11,
stringparam12,
stringparam13,
stringparam14,
stringparam15,
stringparam16,
stringparam17,
stringparam18,
stringparam19
};
int main(int argc, const char * argv[])
{
std::map<std::string,int> string_map = {
{"stringparam00",0},
{"stringparam01",0},
{"stringparam02",0},
{"stringparam03",0},
{"stringparam04",0},
{"stringparam05",0},
{"stringparam06",0},
{"stringparam07",0},
{"stringparam08",0},
{"stringparam09",0},
{"stringparam10",0},
{"stringparam11",0},
{"stringparam12",0},
{"stringparam13",0},
{"stringparam14",0},
{"stringparam15",0},
{"stringparam16",0},
{"stringparam17",0},
{"stringparam18",0},
{"stringparam19",0}
};
std::unordered_map<std::string,int> unordered_string_map = {
{"stringparam00",0},
{"stringparam01",0},
{"stringparam02",0},
{"stringparam03",0},
{"stringparam04",0},
{"stringparam05",0},
{"stringparam06",0},
{"stringparam07",0},
{"stringparam08",0},
{"stringparam09",0},
{"stringparam10",0},
{"stringparam11",0},
{"stringparam12",0},
{"stringparam13",0},
{"stringparam14",0},
{"stringparam15",0},
{"stringparam16",0},
{"stringparam17",0},
{"stringparam18",0},
{"stringparam19",0}
};
std::map<StringEnum,int> enum_map = {
{StringEnum::stringparam00,0},
{StringEnum::stringparam01,0},
{StringEnum::stringparam02,0},
{StringEnum::stringparam03,0},
{StringEnum::stringparam04,0},
{StringEnum::stringparam05,0},
{StringEnum::stringparam06,0},
{StringEnum::stringparam07,0},
{StringEnum::stringparam08,0},
{StringEnum::stringparam09,0},
{StringEnum::stringparam10,0},
{StringEnum::stringparam11,0},
{StringEnum::stringparam12,0},
{StringEnum::stringparam13,0},
{StringEnum::stringparam14,0},
{StringEnum::stringparam15,0},
{StringEnum::stringparam16,0},
{StringEnum::stringparam17,0},
{StringEnum::stringparam18,0},
{StringEnum::stringparam19,0}
};
int res = 0;
std::chrono::high_resolution_clock::time_point t = std::chrono::high_resolution_clock::now();
for(int i=0;i<10000000;++i)
{
res += string_map.find("stringparam10")->second;
}
auto duration = std::chrono::high_resolution_clock::now() - t;
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() << std::endl;
t = std::chrono::high_resolution_clock::now();
for(int i=0;i<10000000;++i)
{
res += unordered_string_map.find("stringparam10")->second;
}
duration = std::chrono::high_resolution_clock::now() - t;
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() << std::endl;
t = std::chrono::high_resolution_clock::now();
for(int i=0;i<10000000;++i)
{
res += enum_map.find(StringEnum::stringparam10)->second;
}
duration = std::chrono::high_resolution_clock::now() - t;
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() << std::endl;
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICB0ZXN0X21hcAovLwovLyAgQ3JlYXRlZCBieSBTZXJnZXkgb24gMTAuMDkuMTQuCi8vICBDb3B5cmlnaHQgKGMpIDIwMTQgU2VyZ2V5IFBlcmVwZWxpdHNhLiBBbGwgcmlnaHRzIHJlc2VydmVkLgovLwoKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8dW5vcmRlcmVkX21hcD4KI2luY2x1ZGUgPGNocm9ubz4KCmVudW0gY2xhc3MgU3RyaW5nRW51bQp7CiAgICBzdHJpbmdwYXJhbTAwLAogICAgc3RyaW5ncGFyYW0wMSwKICAgIHN0cmluZ3BhcmFtMDIsCiAgICBzdHJpbmdwYXJhbTAzLAogICAgc3RyaW5ncGFyYW0wNCwKICAgIHN0cmluZ3BhcmFtMDUsCiAgICBzdHJpbmdwYXJhbTA2LAogICAgc3RyaW5ncGFyYW0wNywKICAgIHN0cmluZ3BhcmFtMDgsCiAgICBzdHJpbmdwY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