#include <iostream>
#include <functional>
#include <unordered_map>
#include <stdio.h>
#include <time.h>
#include <sstream>
#include <array>
#include <thread>
#include <chrono>
using MAP = std::unordered_map<std::string, std::string>;
const unsigned int ArraySize = 50000;
std::array<MAP, ArraySize> mapArr;
std::array<MAP, ArraySize> dstMap1;
std::array<MAP, ArraySize> dstMap2;
template<typename T, typename ... Args>
void printRuntime(T fn, Args&& ... args)
{
? ? auto cb = std::bind(fn, std::forward<Args>(args) ...);
? ? auto start1 = std::chrono::steady_clock::now();
? ? // std::this_thread::sleep_for(std::chrono::seconds(1));
? ? cb();
? ? auto end1 = std::chrono::steady_clock::now();
? ? auto time1 = (end1 - start1).count();
? ? std::cout << "Running time1: " << time1 << std::endl;
}
void mapTest1(std::array<MAP, ArraySize>& mapArr, std::array<MAP, ArraySize>& dstMap1)
{
? ? for(int i= 0; i < ArraySize; i++)
? ? {
? ? ? ? for(const auto& v : mapArr[i])
? ? ? ? {
? ? ? ? ? ? dstMap1[i].insert(std::pair<std::string, std::string>(v.first, v.second));
? ? ? ? }
? ? }
}
void mapTest2(std::array<MAP, ArraySize>& mapArr, std::array<MAP, ArraySize>& dstMap2)
{
? ? for(int i= 0; i < ArraySize; i++)
? ? {
? ? ? ? dstMap2[i] = std::move(mapArr[i]);
? ? }
}
int main()
{
? ? for(auto& v : mapArr)
? ? {
? ? ? ? v.insert(std::pair<std::string, std::string>("123456789", "abcdefg"));
? ? ? ? v.insert(std::pair<std::string, std::string>("123456789", "abcdefg"));
? ? ? ? v.insert(std::pair<std::string, std::string>("123456789", "abcdefg"));
? ? ? ? v.insert(std::pair<std::string, std::string>("123456789", "abcdefg"));
? ? ? ? v.insert(std::pair<std::string, std::string>("123456789", "abcdefg"));
? ? ? ? v.insert(std::pair<std::string, std::string>("123456789", "abcdefg"));
? ? ? ? v.insert(std::pair<std::string, std::string>("123456789", "abcdefg"));
? ? ? ? v.insert(std::pair<std::string, std::string>("123456789", "abcdefg"));
? ? ? ? v.insert(std::pair<std::string, std::string>("123456789", "abcdefg"));
? ? }
? ? printRuntime(mapTest1, mapArr, dstMap1);
? ? printRuntime(mapTest2, mapArr, dstMap2);
}