写程序时,面临用Map还是unordered_map,总是很纠结,于是写了个程序进行测试

Map 与 unordered_map 横向与纵向测试,附带原始数据与测试程序

简单数据(4 Byte)

首先先上一组小数据

测试项目 数据范围 耗时(us)
Map写入 1000 94
——Map读取 1000 62
unordered_map写入 1000 101
——unordered_map读取 1000 61

可以看到数据较小时候是Map占优势

再来一组中等数据

测试项目 数据范围 耗时(us)
Map写入 10000 1682
——Map读取 10000 2703
unordered_map写入 10000 1160
——unordered_map读取 10000 677

大于1000后就是unordered_map优势更大

特大数据下情况是

测试项目 数据范围 耗时(us)
Map写入 1000000 855782
——Map读取 1000000 811670
unordered_map写入 1000000 267515
——unordered_map读取 1000000 118495

大数据便是unordered_map完全碾压

复杂数据(32 Byte)

有人可能会说当数据很复杂时unordered_map容易引发冲突

测试项目 数据范围 耗时(us)
Map写入 10000 4064
——Map读取 10000 4569
unordered_map写入 10000 2139
——unordered_map读取 10000 1716

和上面比较,发现数据变得更复杂时,Map更不如unordered_map了

重载和函数的速度

另外测试还发现,无论是写入还是读取,用重载方法都要比函数慢,其中读取慢的更多。

测试项目 数据范围 耗时(us)
Map重载写入 1000000 906477
——Map重载读取 1000000 1115637
Map函数写入 1000000 855782
——Map函数读取 1000000 811670
测试项目 数据范围 耗时(us)
unordered_map重载写入 1000000 284470
——unordered_map重载读取 1000000 276208
unordered_map函数写入 1000000 267515
——unordered_map函数读取 1000000 118495

总结

根据上面的数据可以分析出

在数据小于1000时,可以采取Map。大于1000,小于10000时,如果需要排序,选用Map,不需要就unordered_map。大于10000的时候没有特殊要求,采用Map。

另外,插入和读取如果有时间刚需,应该采用函数,而不是重载

原始数据与测试程序

如果有人需要原始数据,可以看看。

int 4

map

operator

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <map>
using namespace std; int main()
{
int start = 0; for (int i = 1; i <= 10000; i++)
rand(); for (int n = 1; n <= 1e6; n *= 10)
for (int m = 1; m <= 1e6; m *= 10)
{
map<int, int> M;
srand(233);
start = clock();
for (int i = 1; i <= n; i++)
M[rand()] = rand();
cout << "|Writing spends |" << clock() - start << '|' << n << '|' << m << '|' << endl;
start = clock();
int temp;
for (int i = 1; i <= m; i++)
M[rand()];
cout << "|Reading spends |" << clock() - start << '|' << n << '|' << m << '|' << endl;
}
return 0;
}
项目 耗时(微秒) 写入次数 读取次数
Writing spends 26 1 1
Reading spends 3 1 1
Writing spends 1 1 10
Reading spends 2 1 10
Writing spends 0 1 100
Reading spends 15 1 100
Writing spends 1 1 1000
Reading spends 134 1 1000
Writing spends 2 1 10000
Reading spends 1781 1 10000
Writing spends 4 1 100000
Reading spends 48145 1 100000
Writing spends 7 1 1000000
Reading spends 823069 1 1000000
Writing spends 7 10 1
Reading spends 1 10 1
Writing spends 1 10 10
Reading spends 2 10 10
Writing spends 1 10 100
Reading spends 13 10 100
Writing spends 1 10 1000
Reading spends 217 10 1000
Writing spends 2 10 10000
Reading spends 2971 10 10000
Writing spends 5 10 100000
Reading spends 119565 10 100000
Writing spends 9 10 1000000
Reading spends 947049 10 1000000
Writing spends 18 100 1
Reading spends 1 100 1
Writing spends 10 100 10
Reading spends 2 100 10
Writing spends 9 100 100
Reading spends 17 100 100
Writing spends 8 100 1000
Reading spends 231 100 1000
Writing spends 11 100 10000
Reading spends 3457 100 10000
Writing spends 14 100 100000
Reading spends 86540 100 100000
Writing spends 24 100 1000000
Reading spends 1350311 100 1000000
Writing spends 166 1000 1
Reading spends 2 1000 1
Writing spends 147 1000 10
Reading spends 3 1000 10
Writing spends 133 1000 100
Reading spends 24 1000 100
Writing spends 132 1000 1000
Reading spends 245 1000 1000
Writing spends 143 1000 10000
Reading spends 3755 1000 10000
Writing spends 200 1000 100000
Reading spends 115802 1000 100000
Writing spends 219 1000 1000000
Reading spends 950769 1000 1000000
Writing spends 2963 10000 1
Reading spends 1 10000 1
Writing spends 2988 10000 10
Reading spends 6 10000 10
Writing spends 2905 10000 100
Reading spends 43 10000 100
Writing spends 4573 10000 1000
Reading spends 1448 10000 1000
Writing spends 3492 10000 10000
Reading spends 12881 10000 10000
Writing spends 2880 10000 100000
Reading spends 101483 10000 100000
Writing spends 2951 10000 1000000
Reading spends 935608 10000 1000000
Writing spends 49535 100000 1
Reading spends 2 100000 1
Writing spends 70612 100000 10
Reading spends 8 100000 10
Writing spends 76232 100000 100
Reading spends 76 100000 100
Writing spends 80457 100000 1000
Reading spends 790 100000 1000
Writing spends 84432 100000 10000
Reading spends 9677 100000 10000
Writing spends 78376 100000 100000
Reading spends 97320 100000 100000
Writing spends 69574 100000 1000000
Reading spends 965508 100000 1000000
Writing spends 903613 1000000 1
Reading spends 3 1000000 1
Writing spends 907309 1000000 10
Reading spends 12 1000000 10
Writing spends 916617 1000000 100
Reading spends 119 1000000 100
Writing spends 917360 1000000 1000
Reading spends 1177 1000000 1000
Writing spends 904860 1000000 10000
Reading spends 12960 1000000 10000
Writing spends 905297 1000000 100000
Reading spends 127472 1000000 100000
Writing spends 906477 1000000 1000000
Reading spends 1115637 1000000 1000000

insert & find

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <map>
using namespace std; int main()
{
int start = 0; for (int i = 1; i <= 10000; i++)
rand(); for (int n = 1; n <= 1e6; n *= 10)
for (int m = 1; m <= 1e6; m *= 10)
{
map<int, int> M;
srand(233);
start = clock();
for (int i = 1; i <= n; i++)
M.insert(make_pair(rand(), rand()));
cout << "|Writing spends |" << clock() - start << '|' << n << '|' << m << '|' << endl;
start = clock();
int temp;
for (int i = 1; i <= m; i++)
M.find(rand());
cout << "|Reading spends |" << clock() - start << '|' << n << '|' << m << '|' << endl;
}
return 0;
}
项目 耗时(微秒) 写入次数 读取次数
Writing spends 26 1 1
Reading spends 1 1 1
Writing spends 1 1 10
Reading spends 1 1 10
Writing spends 0 1 100
Reading spends 2 1 100
Writing spends 0 1 1000
Reading spends 12 1 1000
Writing spends 1 1 10000
Reading spends 109 1 10000
Writing spends 1 1 100000
Reading spends 1086 1 100000
Writing spends 1 1 1000000
Reading spends 10757 1 1000000
Writing spends 3 10 1
Reading spends 1 10 1
Writing spends 2 10 10
Reading spends 1 10 10
Writing spends 1 10 100
Reading spends 3 10 100
Writing spends 1 10 1000
Reading spends 19 10 1000
Writing spends 1 10 10000
Reading spends 187 10 10000
Writing spends 1 10 100000
Reading spends 1813 10 100000
Writing spends 2 10 1000000
Reading spends 18350 10 1000000
Writing spends 19 100 1
Reading spends 4 100 1
Writing spends 12 100 10
Reading spends 1 100 10
Writing spends 7 100 100
Reading spends 5 100 100
Writing spends 7 100 1000
Reading spends 37 100 1000
Writing spends 7 100 10000
Reading spends 367 100 10000
Writing spends 11 100 100000
Reading spends 3599 100 100000
Writing spends 11 100 1000000
Reading spends 35590 100 1000000
Writing spends 259 1000 1
Reading spends 2 1000 1
Writing spends 107 1000 10
Reading spends 2 1000 10
Writing spends 99 1000 100
Reading spends 9 1000 100
Writing spends 94 1000 1000
Reading spends 62 1000 1000
Writing spends 95 1000 10000
Reading spends 565 1000 10000
Writing spends 99 1000 100000
Reading spends 5584 1000 100000
Writing spends 101 1000 1000000
Reading spends 55971 1000 1000000
Writing spends 1732 10000 1
Reading spends 1 10000 1
Writing spends 2230 10000 10
Reading spends 4 10000 10
Writing spends 2644 10000 100
Reading spends 28 10000 100
Writing spends 1633 10000 1000
Reading spends 188 10000 1000
Writing spends 1682 10000 10000
Reading spends 2703 10000 10000
Writing spends 1638 10000 100000
Reading spends 14327 10000 100000
Writing spends 1546 10000 1000000
Reading spends 142330 10000 1000000
Writing spends 67350 100000 1
Reading spends 2 100000 1
Writing spends 69654 100000 10
Reading spends 4 100000 10
Writing spends 64137 100000 100
Reading spends 39 100000 100
Writing spends 67940 100000 1000
Reading spends 436 100000 1000
Writing spends 63069 100000 10000
Reading spends 4709 100000 10000
Writing spends 86477 100000 100000
Reading spends 64116 100000 100000
Writing spends 67929 100000 1000000
Reading spends 370789 100000 1000000
Writing spends 768626 1000000 1
Reading spends 2 1000000 1
Writing spends 850479 1000000 10
Reading spends 12 1000000 10
Writing spends 857980 1000000 100
Reading spends 84 1000000 100
Writing spends 854080 1000000 1000
Reading spends 899 1000000 1000
Writing spends 856615 1000000 10000
Reading spends 9960 1000000 10000
Writing spends 871467 1000000 100000
Reading spends 111029 1000000 100000
Writing spends 855782 1000000 1000000
Reading spends 811670 1000000 1000000

unordered_map

operator

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <tr1/unordered_map>
using namespace std;
using namespace tr1; int main()
{
int start = 0; for (int i = 1; i <= 10000; i++)
rand(); for (int n = 1; n <= 1e6; n *= 10)
for (int m = 1; m <= 1e6; m *= 10)
{
unordered_map<int, int> M;
srand(233);
start = clock();
for (int i = 1; i <= n; i++)
M[rand()] = rand();
cout << "|Writing spends |" << clock() - start << '|' << n << '|' << m << '|' << endl;
start = clock();
int temp;
for (int i = 1; i <= m; i++)
M[rand()];
cout << "|Reading spends |" << clock() - start << '|' << n << '|' << m << '|' << endl;
}
return 0;
}
项目 耗时(微秒) 写入次数 读取次数
Writing spends 22 1 1
Reading spends 3 1 1
Writing spends 1 1 10
Reading spends 2 1 10
Writing spends 1 1 100
Reading spends 15 1 100
Writing spends 2 1 1000
Reading spends 98 1 1000
Writing spends 2 1 10000
Reading spends 973 1 10000
Writing spends 2 1 100000
Reading spends 18905 1 100000
Writing spends 7 1 1000000
Reading spends 304928 1 1000000
Writing spends 6 10 1
Reading spends 0 10 1
Writing spends 1 10 10
Reading spends 2 10 10
Writing spends 1 10 100
Reading spends 211558 10 100
Writing spends 2 10 1000
Reading spends 83 10 1000
Writing spends 1 10 10000
Reading spends 816 10 10000
Writing spends 2 10 100000
Reading spends 18775 10 100000
Writing spends 9 10 1000000
Reading spends 331476 10 1000000
Writing spends 18 100 1
Reading spends 1 100 1
Writing spends 10 100 10
Reading spends 2 100 10
Writing spends 9 100 100
Reading spends 10 100 100
Writing spends 10 100 1000
Reading spends 84 100 1000
Writing spends 21 100 10000
Reading spends 856 100 10000
Writing spends 16 100 100000
Reading spends 19406 100 100000
Writing spends 20 100 1000000
Reading spends 344753 100 1000000
Writing spends 93 1000 1
Reading spends 1 1000 1
Writing spends 98 1000 10
Reading spends 1 1000 10
Writing spends 95 1000 100
Reading spends 5 1000 100
Writing spends 94 1000 1000
Reading spends 81 1000 1000
Writing spends 106 1000 10000
Reading spends 749 1000 10000
Writing spends 97 1000 100000
Reading spends 20981 1000 100000
Writing spends 110 1000 1000000
Reading spends 330149 1000 1000000
Writing spends 858 10000 1
Reading spends 1 10000 1
Writing spends 858 10000 10
Reading spends 1 10000 10
Writing spends 837 10000 100
Reading spends 7 10000 100
Writing spends 841 10000 1000
Reading spends 59 10000 1000
Writing spends 850 10000 10000
Reading spends 950 10000 10000
Writing spends 849 10000 100000
Reading spends 27480 10000 100000
Writing spends 919 10000 1000000
Reading spends 338245 10000 1000000
Writing spends 33755 100000 1
Reading spends 1 100000 1
Writing spends 29546 100000 10
Reading spends 3 100000 10
Writing spends 31192 100000 100
Reading spends 97 100000 100
Writing spends 30126 100000 1000
Reading spends 216 100000 1000
Writing spends 37193 100000 10000
Reading spends 1996 100000 10000
Writing spends 32065 100000 100000
Reading spends 39717 100000 100000
Writing spends 17520 100000 1000000
Reading spends 473755 100000 1000000
Writing spends 480733 1000000 1
Reading spends 2 1000000 1
Writing spends 345884 1000000 10
Reading spends 44 1000000 10
Writing spends 284269 1000000 100
Reading spends 24 1000000 100
Writing spends 283844 1000000 1000
Reading spends 223 1000000 1000
Writing spends 278945 1000000 10000
Reading spends 2068 1000000 10000
Writing spends 280158 1000000 100000
Reading spends 189937 1000000 100000
Writing spends 284470 1000000 1000000
Reading spends 376208 1000000 1000000

insert & find

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <tr1/unordered_map>
using namespace std;
using namespace tr1; int main()
{
int start = 0; for (int i = 1; i <= 10000; i++)
rand(); for (int n = 1; n <= 1e6; n *= 10)
for (int m = 1; m <= 1e6; m *= 10)
{
unordered_map<int, int> M;
srand(233);
start = clock();
for (int i = 1; i <= n; i++)
M.insert(make_pair(rand(), rand()));
cout << "|Writing spends |" << clock() - start << '|' << n << '|' << m << '|' << endl;
start = clock();
int temp;
for (int i = 1; i <= m; i++)
M.find(rand());
cout << "|Reading spends |" << clock() - start << '|' << n << '|' << m << '|' << endl;
}
return 0;
}
项目 耗时(微秒) 写入次数 读取次数
Writing spends 24 1 1
Reading spends 1 1 1
Writing spends 1 1 10
Reading spends 1 1 10
Writing spends 1 1 100
Reading spends 2 1 100
Writing spends 1 1 1000
Reading spends 18 1 1000
Writing spends 1 1 10000
Reading spends 174 1 10000
Writing spends 1 1 100000
Reading spends 1720 1 100000
Writing spends 1 1 1000000
Reading spends 17160 1 1000000
Writing spends 2 10 1
Reading spends 1 10 1
Writing spends 1 10 10
Reading spends 1 10 10
Writing spends 1 10 100
Reading spends 4 10 100
Writing spends 1 10 1000
Reading spends 25 10 1000
Writing spends 1 10 10000
Reading spends 238 10 10000
Writing spends 1 10 100000
Reading spends 2361 10 100000
Writing spends 1 10 1000000
Reading spends 23766 10 1000000
Writing spends 18 100 1
Reading spends 6 100 1
Writing spends 12 100 10
Reading spends 4 100 10
Writing spends 13 100 100
Reading spends 13 100 100
Writing spends 17 100 1000
Reading spends 45 100 1000
Writing spends 14 100 10000
Reading spends 251 100 10000
Writing spends 12 100 100000
Reading spends 2390 100 100000
Writing spends 12 100 1000000
Reading spends 24286 100 1000000
Writing spends 126 1000 1
Reading spends 1 1000 1
Writing spends 98 1000 10
Reading spends 1 1000 10
Writing spends 93 1000 100
Reading spends 3 1000 100
Writing spends 101 1000 1000
Reading spends 61 1000 1000
Writing spends 104 1000 10000
Reading spends 259 1000 10000
Writing spends 97 1000 100000
Reading spends 2492 1000 100000
Writing spends 96 1000 1000000
Reading spends 25507 1000 1000000
Writing spends 1587 10000 1
Reading spends 1 10000 1
Writing spends 1013 10000 10
Reading spends 1 10000 10
Writing spends 823 10000 100
Reading spends 8 10000 100
Writing spends 840 10000 1000
Reading spends 54 10000 1000
Writing spends 1160 10000 10000
Reading spends 677 10000 10000
Writing spends 813 10000 100000
Reading spends 4968 10000 100000
Writing spends 808 10000 1000000
Reading spends 38649 10000 1000000
Writing spends 28790 100000 1
Reading spends 11 100000 1
Writing spends 45300 100000 10
Reading spends 5 100000 10
Writing spends 34463 100000 100
Reading spends 14 100000 100
Writing spends 35388 100000 1000
Reading spends 113 100000 1000
Writing spends 32767 100000 10000
Reading spends 2677 100000 10000
Writing spends 31524 100000 100000
Reading spends 13741 100000 100000
Writing spends 33473 100000 1000000
Reading spends 100586 100000 1000000
Writing spends 300962 1000000 1
Reading spends 1 1000000 1
Writing spends 442759 1000000 10
Reading spends 2 1000000 10
Writing spends 270830 1000000 100
Reading spends 10 1000000 100
Writing spends 270029 1000000 1000
Reading spends 124 1000000 1000
Writing spends 268652 1000000 10000
Reading spends 1192 1000000 10000
Writing spends 269445 1000000 100000
Reading spends 12717 1000000 100000
Writing spends 267515 1000000 1000000
Reading spends 118495 1000000 1000000

Btye 32

map

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <map>
using namespace std; inline __uint128_t rand128()
{
return rand() | ((__uint128_t)rand() << 32) | ((__uint128_t)rand() << 64) | ((__uint128_t)rand() << 96);
} int main()
{
int start = 0; for (int i = 1; i <= 10000; i++)
rand(); for (int n = 1; n <= 1e6; n *= 10)
for (int m = 1; m <= 1e6; m *= 10)
{
map<pair<__uint128_t, __uint128_t>, int> M;
srand(233);
start = clock();
for (int i = 1; i <= n; i++)
M.insert(make_pair(make_pair(rand128(), rand128()), rand()));
cout << "|Writing spends |" << clock() - start << '|' << n << '|' << m << '|' << endl;
start = clock();
int temp;
for (int i = 1; i <= m; i++)
M.find(make_pair(rand128(), rand128()));
cout << "|Reading spends |" << clock() - start << '|' << n << '|' << m << '|' << endl;
}
return 0;
}
项目 耗时(微秒) 写入次数 读取次数
Writing spends 24 1 1
Reading spends 0 1 1
Writing spends 1 1 10
Reading spends 2 1 10
Writing spends 1 1 100
Reading spends 9 1 100
Writing spends 1 1 1000
Reading spends 70 1 1000
Writing spends 1 1 10000
Reading spends 693 1 10000
Writing spends 1 1 100000
Reading spends 7061 1 100000
Writing spends 2 1 1000000
Reading spends 70166 1 1000000
Writing spends 4 10 1
Reading spends 1 10 1
Writing spends 3 10 10
Reading spends 2 10 10
Writing spends 1 10 100
Reading spends 9 10 100
Writing spends 1 10 1000
Reading spends 83 10 1000
Writing spends 2 10 10000
Reading spends 802 10 10000
Writing spends 2 10 100000
Reading spends 7936 10 100000
Writing spends 3 10 1000000
Reading spends 81096 10 1000000
Writing spends 26 100 1
Reading spends 2 100 1
Writing spends 18 100 10
Reading spends 3 100 10
Writing spends 18 100 100
Reading spends 13 100 100
Writing spends 18 100 1000
Reading spends 103 100 1000
Writing spends 17 100 10000
Reading spends 996 100 10000
Writing spends 20 100 100000
Reading spends 9949 100 100000
Writing spends 19 100 1000000
Reading spends 100397 100 1000000
Writing spends 226 1000 1
Reading spends 1 1000 1
Writing spends 166 1000 10
Reading spends 3 1000 10
Writing spends 164 1000 100
Reading spends 15 1000 100
Writing spends 164 1000 1000
Reading spends 133 1000 1000
Writing spends 167 1000 10000
Reading spends 1278 1000 10000
Writing spends 168 1000 100000
Reading spends 12895 1000 100000
Writing spends 174 1000 1000000
Reading spends 127273 1000 1000000
Writing spends 2917 10000 1
Reading spends 2 10000 1
Writing spends 2730 10000 10
Reading spends 4 10000 10
Writing spends 3344 10000 100
Reading spends 36 10000 100
Writing spends 5555 10000 1000
Reading spends 670 10000 1000
Writing spends 4300 10000 10000
Reading spends 4064 10000 10000
Writing spends 4569 10000 100000
Reading spends 35972 10000 100000
Writing spends 3696 10000 1000000
Reading spends 235334 10000 1000000
Writing spends 80213 100000 1
Reading spends 1 100000 1
Writing spends 75975 100000 10
Reading spends 7 100000 10
Writing spends 72787 100000 100
Reading spends 61 100000 100
Writing spends 72727 100000 1000
Reading spends 620 100000 1000
Writing spends 78175 100000 10000
Reading spends 6618 100000 10000
Writing spends 85278 100000 100000
Reading spends 74804 100000 100000
Writing spends 69928 100000 1000000
Reading spends 541858 100000 1000000
Writing spends 937039 1000000 1
Reading spends 2 1000000 1
Writing spends 996383 1000000 10
Reading spends 12 1000000 10
Writing spends 997665 1000000 100
Reading spends 116 1000000 100
Writing spends 1001405 1000000 1000
Reading spends 1115 1000000 1000
Writing spends 994444 1000000 10000
Reading spends 11241 1000000 10000
Writing spends 1009323 1000000 100000
Reading spends 126125 1000000 100000
Writing spends 998410 1000000 1000000
Reading spends 1002439 1000000 1000000

unordered_map

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <tr1/unordered_map>
using namespace std;
using namespace tr1; struct hashfunc
{
inline size_t operator()(const pair<__uint128_t, __uint128_t> &i) const
{
return tr1::hash<long long>()((long long)i.first) ^ tr1::hash<long long>()((long long)(i.first >> 64)) ^ tr1::hash<long long>()((long long)i.second) ^ tr1::hash<long long>()((long long)(i.second >> 64));
}
}; inline __uint128_t rand128()
{
return rand() | ((__uint128_t)rand() << 32) | ((__uint128_t)rand() << 64) | ((__uint128_t)rand() << 96);
} int main()
{
int start = 0; for (int i = 1; i <= 10000; i++)
rand(); for (int n = 1; n <= 1e6; n *= 10)
for (int m = 1; m <= 1e6; m *= 10)
{
unordered_map<pair<__uint128_t, __uint128_t>, int, hashfunc> M;
srand(233);
start = clock();
for (int i = 1; i <= n; i++)
M.insert(make_pair(make_pair(rand128(), rand128()), rand()));
cout << "|Writing spends |" << clock() - start << '|' << n << '|' << m << '|' << endl;
start = clock();
int temp;
for (int i = 1; i <= m; i++)
M.find(make_pair(rand128(), rand128()));
cout << "|Reading spends |" << clock() - start << '|' << n << '|' << m << '|' << endl;
}
return 0;
}
项目 耗时(微秒) 写入次数 读取次数
Writing spends 21 1 1
Reading spends 2 1 1
Writing spends 1 1 10
Reading spends 1 1 10
Writing spends 1 1 100
Reading spends 9 1 100
Writing spends 1 1 1000
Reading spends 76 1 1000
Writing spends 1 1 10000
Reading spends 744 1 10000
Writing spends 1 1 100000
Reading spends 7466 1 100000
Writing spends 2 1 1000000
Reading spends 74453 1 1000000
Writing spends 3 10 1
Reading spends 0 10 1
Writing spends 2 10 10
Reading spends 2 10 10
Writing spends 2 10 100
Reading spends 9 10 100
Writing spends 2 10 1000
Reading spends 85 10 1000
Writing spends 2 10 10000
Reading spends 836 10 10000
Writing spends 1 10 100000
Reading spends 8370 10 100000
Writing spends 2 10 1000000
Reading spends 84176 10 1000000
Writing spends 27 100 1
Reading spends 1 100 1
Writing spends 17 100 10
Reading spends 2 100 10
Writing spends 15 100 100
Reading spends 9 100 100
Writing spends 14 100 1000
Reading spends 83 100 1000
Writing spends 14 100 10000
Reading spends 825 100 10000
Writing spends 15 100 100000
Reading spends 8127 100 100000
Writing spends 20 100 1000000
Reading spends 81937 100 1000000
Writing spends 211 1000 1
Reading spends 1 1000 1
Writing spends 164 1000 10
Reading spends 2 1000 10
Writing spends 143 1000 100
Reading spends 9 1000 100
Writing spends 160 1000 1000
Reading spends 84 1000 1000
Writing spends 144 1000 10000
Reading spends 839 1000 10000
Writing spends 161 1000 100000
Reading spends 8344 1000 100000
Writing spends 161 1000 1000000
Reading spends 84518 1000 1000000
Writing spends 2609 10000 1
Reading spends 1 10000 1
Writing spends 2341 10000 10
Reading spends 8 10000 10
Writing spends 1959 10000 100
Reading spends 18 10000 100
Writing spends 1548 10000 1000
Reading spends 193 10000 1000
Writing spends 2139 10000 10000
Reading spends 1716 10000 10000
Writing spends 1929 10000 100000
Reading spends 14391 10000 100000
Writing spends 1573 10000 1000000
Reading spends 128671 10000 1000000
Writing spends 37911 100000 1
Reading spends 1 100000 1
Writing spends 64046 100000 10
Reading spends 3 100000 10
Writing spends 29753 100000 100
Reading spends 18 100000 100
Writing spends 24535 100000 1000
Reading spends 211 100000 1000
Writing spends 34458 100000 10000
Reading spends 1982 100000 10000
Writing spends 41840 100000 100000
Reading spends 30702 100000 100000
Writing spends 44858 100000 1000000
Reading spends 195389 100000 1000000
Writing spends 426814 1000000 1
Reading spends 2 1000000 1
Writing spends 637874 1000000 10
Reading spends 3 1000000 10
Writing spends 405023 1000000 100
Reading spends 28 1000000 100
Writing spends 388910 1000000 1000
Reading spends 301 1000000 1000
Writing spends 402672 1000000 10000
Reading spends 2515 1000000 10000
Writing spends 393968 1000000 100000
Reading spends 29590 1000000 100000
Writing spends 395403 1000000 1000000
Reading spends 250795 1000000 1000000

Map 与 unordered_map 横向与纵向测试,附带原始数据与测试程序的更多相关文章

  1. map 与 unordered_map

    两者效率对比: #include <iostream> #include <string> #include <map> #include <unordere ...

  2. 关于c++ STL map 和 unordered_map 的效率的对比测试

    本文采用在随机读取和插入的情况下测试map和unordered_map的效率 笔者的电脑是台渣机,现给出配置信息 处理器 : Intel Pentium(R) CPU G850 @ 2.90GHz × ...

  3. map和unordered_map的差别和使用

    map和unordered_map的差别还不知道或者搞不清unordered_map和map是什么的,请见:http://blog.csdn.net/billcyj/article/details/7 ...

  4. 【转】Map 与 Unordered_map

    map和unordered_map的差别和使用 map和unordered_map的差别还不知道或者搞不清unordered_map和map是什么的,请见:http://blog.csdn.net/b ...

  5. C++ map与unordered_map

    map与unordered_map对比 map unordered_map 红黑树(非严格二叉平衡搜索树)实现 哈希表实现 有序 无序 -- 查找时间复杂度为O(1),非常快 空间消耗较大 空间消耗较 ...

  6. STL中的map和unordered_map

    STL中的map和unordered_map map 头文件:#include 原理:std::map的内部实现了一颗红黑树,有对其键值进行排序的功能,所以map是一个有序的容器,map中的每一个元素 ...

  7. C++中map和unordered_map的用法

    1. 简介 map和unordered_map都是c++中可以充当字典(key-value)来用的数据类型,但是其基本实现是不一样的. 2. map 对于map的底层原理,是通过红黑树(一种非严格意义 ...

  8. map和unordered_map使用小结

    map和unordered_map unordered_map简介: #include <cstdio> #include <iostream> #include <un ...

  9. 原 c++中map与unordered_map的区别

    c++中map与unordered_map的区别 头文件 map: #include < map > unordered_map: #include < unordered_map ...

随机推荐

  1. 13、linux中用户和用户组

    linux是多用户多进程的系统: 每个文件和进程都需要应对一个用户和用户组: linux系统通过uid和gid来识别用户和组的: 一个用户必须要有唯一的uid和一个主组来识别身份,不同的用户可以使用同 ...

  2. 41.1、shell编程案例

    1.案例1(表达式案例): 开发shell脚本分别实现以定义变量,脚本传参以及read读入的方式比较2个整数大小.用条件表达式(禁if) 进行判断并以屏幕输出的方式提醒用户比较结果: [root@ba ...

  3. c++11 线程间同步---利用std::condition_variable实现

    1.前言 很多时候,我们在写程序的时候,多多少少会遇到下面种需求 一个产品的大致部分流程,由工厂生产,然后放入仓库,最后由销售员提单卖出去这样. 在实际中,仓库的容量的有限的,也就是说,工厂不能一直生 ...

  4. Linux:CentOS-7配置VMware-15.5与本机IP同网段

    确认本机IP ctrl+R:输入cmd 回车 输入命令:ipconfig  可以看出一下信息:本机ip: 192.168.1.162网关:192.168.1.1DNS服务器:192.168.1.1 设 ...

  5. SpringMVC(5)数据绑定-2

    在SpringMVC(4)数据绑定-1中我们介绍了如何用@RequestParam来绑定数据,下面我们来看一下其它几个数据绑定注解的使用方法. 1.@PathVariable 用来绑定URL模板变量值 ...

  6. buu 新年快乐

    一.查壳 发现是upx的壳. 二.拖入ida,发现要先脱壳. 题外话.总结一下手动脱壳,esp定律: 1.先单步到只有esp红色时,右键数据窗口跟随. 2.到数据窗口后,左键硬件访问,byte和wor ...

  7. java基础---泛型机制

    从java5 开始增加泛型机制,用于明确集合中可以放入的元素类型,只在编译时期有效,运行时不区分是什么类型. 格式:<数据类型> 泛型的本质是参数化类型,让数据类型作为参数传递,E相当于形 ...

  8. Git初始化本地已有项目

    1.初始化仓库 git init 2.remote git remote add origin 仓库地址 3.从远程分支拉取master分支并与本地master分支合并 git pull origin ...

  9. java并发编程基础——线程的创建

    一.基础概念 1.进程和线程 进程:每个进程都有独立的代码和数据空间(进程上下文),进程间的切换会有较大的开销,一个进程包含1--n个线程.(进程是资源分配的最小单位) 线程:同一类线程共享代码和数据 ...

  10. aptitude软件状态标志i、v、p

    输出的结果分三栏,分别为状态.包名和描述.而状态则由p.i.v等字母表示.查询后才知道这些标识的含义是这样的: i - 包已经成功安装,并且所有依赖都满足. c - 包已经被移除,但是配置文件被保留. ...