Skip to content

Commit 2201ae6

Browse files
authored
Merge pull request #48 from Alinshans/v2
🚀 Update test.
2 parents 655405e + 1fc58d0 commit 2201ae6

File tree

8 files changed

+43
-39
lines changed

8 files changed

+43
-39
lines changed

Test/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
In this file [test.h](https://github.com/Alinshans/MyTinySTL/blob/master/MyTinySTL/Test/test.h), I used two class to implement a simple test framework, and defined a lot of macros to package testing process.
1616

1717
## 测试内容 (Test content)
18-
[test.h](https://github.com/Alinshans/MyTinySTL/blob/master/MyTinySTL/Test/test.h) 中定义了两个宏,`PERFORMANCE_TEST_ON``MEMORY_IS_ENOUGH``PERFORMANCE_TEST_ON` 宏定义为 `1`,开启性能测试,`MEMORY_IS_ENOUGH` 宏定义为 `1`,增大测试数据(更多内存消耗)。默认 `PERFORMANCE_TEST_ON``1``MEMORY_IS_ENOUGH``0`。<br>
19-
In this file [test.h](https://github.com/Alinshans/MyTinySTL/blob/master/MyTinySTL/Test/test.h), I defined two marcos: `PERFORMANCE_TEST_ON` and `MEMORY_IS_ENOUGH`. If `PERFORMANCE_TEST_ON` is defined as `1`, it will run the performance test, if `MEMORY_IS_ENOUGH` is defined as `1`, it will take larger test data(which will consume more memory). By default, `PERFORMANCE_TEST_ON` is `1` and `MEMORY_IS_ENOUGH` is `0`.
18+
[test.h](https://github.com/Alinshans/MyTinySTL/blob/master/MyTinySTL/Test/test.h) 中定义了两个宏,`PERFORMANCE_TEST_ON``MEMORY_IS_ENOUGH``PERFORMANCE_TEST_ON` 宏定义为 `1`,开启性能测试,`MEMORY_IS_ENOUGH` 宏定义为 `1`,增大测试数据(更多内存消耗)。默认 `PERFORMANCE_TEST_ON``1``MEMORY_IS_ENOUGH``0`**建议电脑内存大小在 8G 及以上时,才运行默认的测试,否则应该为每个 test 的性能测试部分手动调小 1 ~ 2 个数量级,比如将 `_M` 的后缀修改为 `_S`,详情见 [test.h](https://github.com/Alinshans/MyTinySTL/blob/master/MyTinySTL/Test/test.h) 中定义的宏。**<br>
19+
In this file [test.h](https://github.com/Alinshans/MyTinySTL/blob/master/MyTinySTL/Test/test.h), I defined two marcos: `PERFORMANCE_TEST_ON` and `MEMORY_IS_ENOUGH`. If `PERFORMANCE_TEST_ON` is defined as `1`, it will run the performance test, if `MEMORY_IS_ENOUGH` is defined as `1`, it will take larger test data(which will consume more memory). By default, `PERFORMANCE_TEST_ON` is `1` and `MEMORY_IS_ENOUGH` is `0`. **It is recommended that you should run the default test when the memory size of your computer is larger or equal to 8GiB, otherwise, you should adjust the amount of test data for each test, e.g., change the `_M` suffix to `_S`, see macros defined in [test.h](https://github.com/Alinshans/MyTinySTL/blob/master/MyTinySTL/Test/test.h) for details.**
2020

2121
测试案例如下:<br>
2222
The test cases are as follows:

Test/list_test.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ void list_test()
101101
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
102102
std::cout << "| sort |";
103103
#if MEMORY_IS_ENOUGH
104-
LIST_SORT_TEST(LEN1 _M, LEN2 _M, LEN3 _M);
105-
#else
106104
LIST_SORT_TEST(LEN1 _S, LEN2 _S, LEN3 _S);
105+
#else
106+
LIST_SORT_TEST(LEN1 _SS, LEN2 _SS, LEN3 _SS);
107107
#endif
108108
std::cout << std::endl;
109109
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;

Test/map_test.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ void map_test()
106106
#if PERFORMANCE_TEST_ON
107107
std::cout << "[--------------------- Performance Testing ---------------------]" << std::endl;
108108
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
109-
std::cout << "| insert |";
109+
std::cout << "| emplace |";
110110
#if MEMORY_IS_ENOUGH
111-
MAP_INSERT_TEST(map, LEN1 _M, LEN2 _M, LEN3 _M);
111+
MAP_EMPLACE_TEST(map, LEN1 _M, LEN2 _M, LEN3 _M);
112112
#else
113-
MAP_INSERT_TEST(map, LEN1 _SS, LEN2 _SS, LEN3 _SS);
113+
MAP_EMPLACE_TEST(map, LEN1 _SS, LEN2 _SS, LEN3 _SS);
114114
#endif
115115
std::cout << std::endl;
116116
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
@@ -182,11 +182,11 @@ void multimap_test()
182182
#if PERFORMANCE_TEST_ON
183183
std::cout << "[--------------------- Performance Testing ---------------------]" << std::endl;
184184
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
185-
std::cout << "| insert |";
185+
std::cout << "| emplace |";
186186
#if MEMORY_IS_ENOUGH
187-
MAP_INSERT_TEST(multimap, LEN1 _S, LEN2 _S, LEN3 _S);
187+
MAP_EMPLACE_TEST(multimap, LEN1 _S, LEN2 _S, LEN3 _S);
188188
#else
189-
MAP_INSERT_TEST(multimap, LEN1 _SS, LEN2 _SS, LEN3 _SS);
189+
MAP_EMPLACE_TEST(multimap, LEN1 _SS, LEN2 _SS, LEN3 _SS);
190190
#endif
191191
std::cout << std::endl;
192192
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;

Test/set_test.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ void set_test()
7474
#if PERFORMANCE_TEST_ON
7575
std::cout << "[--------------------- Performance Testing ---------------------]" << std::endl;
7676
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
77-
std::cout << "| insert |";
77+
std::cout << "| emplace |";
7878
#if MEMORY_IS_ENOUGH
79-
CON_TEST_P1(set<int>, insert, rand(), LEN1 _S, LEN2 _S, LEN3 _S);
79+
CON_TEST_P1(set<int>, emplace, rand(), LEN1 _S, LEN2 _S, LEN3 _S);
8080
#else
81-
CON_TEST_P1(set<int>, insert, rand(), LEN1 _SS, LEN2 _SS, LEN3 _SS);
81+
CON_TEST_P1(set<int>, emplace, rand(), LEN1 _SS, LEN2 _SS, LEN3 _SS);
8282
#endif
8383
std::cout << std::endl;
8484
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
@@ -146,11 +146,11 @@ void multiset_test()
146146
#if PERFORMANCE_TEST_ON
147147
std::cout << "[--------------------- Performance Testing ---------------------]" << std::endl;
148148
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
149-
std::cout << "| insert |";
149+
std::cout << "| emplace |";
150150
#if MEMORY_IS_ENOUGH
151-
CON_TEST_P1(multiset<int>, insert, rand(), LEN1 _S, LEN2 _S, LEN3 _S);
151+
CON_TEST_P1(multiset<int>, emplace, rand(), LEN1 _S, LEN2 _S, LEN3 _S);
152152
#else
153-
CON_TEST_P1(multiset<int>, insert, rand(), LEN1 _SS, LEN2 _SS, LEN3 _SS);
153+
CON_TEST_P1(multiset<int>, emplace, rand(), LEN1 _SS, LEN2 _SS, LEN3 _SS);
154154
#endif
155155
std::cout << std::endl;
156156
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;

Test/test.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#include "algorithm_performance_test.h"
1+
#ifdef _MSC_VER
2+
#define _SCL_SECURE_NO_WARNINGS
3+
#endif // _MSC_VER
4+
5+
#include "algorithm_performance_test.h"
26
#include "algorithm_test.h"
37
#include "vector_test.h"
48
#include "list_test.h"

Test/test.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -631,14 +631,14 @@ void test_len(size_t len1, size_t len2, size_t len3, size_t wide)
631631
std::cout << std::setw(WIDE) << t; \
632632
} while(0)
633633

634-
#define MAP_INSERT_DO_TEST(mode, con, count) do { \
634+
#define MAP_EMPLACE_DO_TEST(mode, con, count) do { \
635635
srand((int)time(0)); \
636636
clock_t start, end; \
637637
mode::con<int, int> c; \
638638
char buf[10]; \
639639
start = clock(); \
640640
for (size_t i = 0; i < count; ++i) \
641-
c.insert(mode::pair<int, int>(rand(), rand())); \
641+
c.emplace(mode::make_pair(rand(), rand())); \
642642
end = clock(); \
643643
int n = static_cast<int>(static_cast<double>(end - start) \
644644
/ CLOCKS_PER_SEC * 1000); \
@@ -671,16 +671,16 @@ void test_len(size_t len1, size_t len2, size_t len3, size_t wide)
671671
FUN_TEST_FORMAT2(mystl::con, fun, arg1, arg2, len2); \
672672
FUN_TEST_FORMAT2(mystl::con, fun, arg1, arg2, len3);
673673

674-
#define MAP_INSERT_TEST(con, len1, len2, len3) \
674+
#define MAP_EMPLACE_TEST(con, len1, len2, len3) \
675675
TEST_LEN(len1, len2, len3, WIDE); \
676676
std::cout << "| std |"; \
677-
MAP_INSERT_DO_TEST(std, con, len1); \
678-
MAP_INSERT_DO_TEST(std, con, len2); \
679-
MAP_INSERT_DO_TEST(std, con, len3); \
677+
MAP_EMPLACE_DO_TEST(std, con, len1); \
678+
MAP_EMPLACE_DO_TEST(std, con, len2); \
679+
MAP_EMPLACE_DO_TEST(std, con, len3); \
680680
std::cout << "\n| mystl |"; \
681-
MAP_INSERT_DO_TEST(mystl, con, len1); \
682-
MAP_INSERT_DO_TEST(mystl, con, len2); \
683-
MAP_INSERT_DO_TEST(mystl, con, len3);
681+
MAP_EMPLACE_DO_TEST(mystl, con, len1); \
682+
MAP_EMPLACE_DO_TEST(mystl, con, len2); \
683+
MAP_EMPLACE_DO_TEST(mystl, con, len3);
684684

685685
#define LIST_SORT_TEST(len1, len2, len3) \
686686
TEST_LEN(len1, len2, len3, WIDE); \
@@ -707,7 +707,7 @@ void test_len(size_t len1, size_t len2, size_t len3, size_t wide)
707707
#endif // !PERFORMANCE_TEST_ON
708708

709709
// 电脑内存是否够大
710-
// 不要随便开启这个选项,除非你确保你的内存有 16G/32G 这么大,并且可用内存还很多
710+
// 如果你的内存只有 8G 或以下,就不要开启这个选项
711711
#ifndef MEMORY_IS_ENOUGH
712712
#define MEMORY_IS_ENOUGH 0
713713
#endif // !MEMORY_IS_ENOUGH

Test/unordered_map_test.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ void unordered_map_test()
9494
#if PERFORMANCE_TEST_ON
9595
std::cout << "[--------------------- Performance Testing ---------------------]" << std::endl;
9696
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
97-
std::cout << "| insert |";
97+
std::cout << "| emplace |";
9898
#if MEMORY_IS_ENOUGH
99-
MAP_INSERT_TEST(unordered_map, LEN1 _M, LEN2 _M, LEN3 _M);
99+
MAP_EMPLACE_TEST(unordered_map, LEN1 _M, LEN2 _M, LEN3 _M);
100100
#else
101-
MAP_INSERT_TEST(unordered_map, LEN1 _S, LEN2 _S, LEN3 _S);
101+
MAP_EMPLACE_TEST(unordered_map, LEN1 _SS, LEN2 _SS, LEN3 _SS);
102102
#endif
103103
std::cout << std::endl;
104104
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
@@ -183,11 +183,11 @@ void unordered_multimap_test()
183183
#if PERFORMANCE_TEST_ON
184184
std::cout << "[--------------------- Performance Testing ---------------------]" << std::endl;
185185
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
186-
std::cout << "| insert |";
186+
std::cout << "| emplace |";
187187
#if MEMORY_IS_ENOUGH
188-
MAP_INSERT_TEST(unordered_multimap, LEN1 _S, LEN2 _S, LEN3 _S);
188+
MAP_EMPLACE_TEST(unordered_multimap, LEN1 _S, LEN2 _S, LEN3 _S);
189189
#else
190-
MAP_INSERT_TEST(unordered_multimap, LEN1 _SS, LEN2 _SS, LEN3 _SS);
190+
MAP_EMPLACE_TEST(unordered_multimap, LEN1 _SS, LEN2 _SS, LEN3 _SS);
191191
#endif
192192
std::cout << std::endl;
193193
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;

Test/unordered_set_test.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ void unordered_set_test()
8787
#if PERFORMANCE_TEST_ON
8888
std::cout << "[--------------------- Performance Testing ---------------------]" << std::endl;
8989
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
90-
std::cout << "| insert |";
90+
std::cout << "| emplace |";
9191
#if MEMORY_IS_ENOUGH
92-
CON_TEST_P1(unordered_set<int>, insert, rand(), LEN1 _S, LEN2 _S, LEN3 _S);
92+
CON_TEST_P1(unordered_set<int>, emplace, rand(), LEN1 _S, LEN2 _S, LEN3 _S);
9393
#else
94-
CON_TEST_P1(unordered_set<int>, insert, rand(), LEN1 _SS, LEN2 _SS, LEN3 _SS);
94+
CON_TEST_P1(unordered_set<int>, emplace, rand(), LEN1 _SS, LEN2 _SS, LEN3 _SS);
9595
#endif
9696
std::cout << std::endl;
9797
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
@@ -171,11 +171,11 @@ void unordered_multiset_test()
171171
#if PERFORMANCE_TEST_ON
172172
std::cout << "[--------------------- Performance Testing ---------------------]" << std::endl;
173173
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;
174-
std::cout << "| insert |";
174+
std::cout << "| emplace |";
175175
#if MEMORY_IS_ENOUGH
176-
CON_TEST_P1(unordered_multiset<int>, insert, rand(), LEN1 _S, LEN2 _S, LEN3 _S);
176+
CON_TEST_P1(unordered_multiset<int>, emplace, rand(), LEN1 _S, LEN2 _S, LEN3 _S);
177177
#else
178-
CON_TEST_P1(unordered_multiset<int>, insert, rand(), LEN1 _SS, LEN2 _SS, LEN3 _SS);
178+
CON_TEST_P1(unordered_multiset<int>, emplace, rand(), LEN1 _SS, LEN2 _SS, LEN3 _SS);
179179
#endif
180180
std::cout << std::endl;
181181
std::cout << "|---------------------|-------------|-------------|-------------|" << std::endl;

0 commit comments

Comments
 (0)