@@ -35,9 +35,9 @@ void BenchmarkMalloc(size_t ntimes, size_t nworks, size_t rounds) {
35
35
for (auto & t : vthread) {
36
36
t.join ();
37
37
}
38
- std::cout << nworks << " 个线程并发执行 " << rounds << " 次,每轮次malloc " << ntimes << " 次: 花费: " << malloc_costtime.load () << " ms\n " ;
39
- std::cout << nworks << " 个线程并发执行 " << rounds << " 轮次,每轮次free " << ntimes << " 次: 花费: " << free_costtime.load () << " ms\n " ;
40
- std::cout << nworks << " 个线程并发malloc& free " << nworks * rounds * ntimes << " 次,总计花费: " << malloc_costtime.load () + free_costtime.load () << " ms\n " ;
38
+ std::cout << nworks << " threads run " << rounds << " times, each round malloc " << ntimes << " times, cost: " << malloc_costtime.load () << " ms\n " ;
39
+ std::cout << nworks << " threads run " << rounds << " times, each round free " << ntimes << " times, cost: " << free_costtime.load () << " ms\n " ;
40
+ std::cout << nworks << " threads run malloc and free " << nworks * rounds * ntimes << " time, total cost: " << malloc_costtime.load () + free_costtime.load () << " ms\n " ;
41
41
}
42
42
43
43
// 单轮次申请释放次数 线程数 轮次
@@ -70,18 +70,16 @@ void BenchmarkConcurrentMalloc(size_t ntimes, size_t nworks, size_t rounds) {
70
70
for (auto & t : vthread) {
71
71
t.join ();
72
72
}
73
- std::cout << nworks << " 个线程并发执行 " << rounds << " 轮次,每轮次concurrent alloc " << ntimes << " 次: 花费: " << malloc_costtime.load () << " ms\n " ;
74
- std::cout << nworks << " 个线程并发执行 " << rounds << " 轮次,每轮次concurrent dealloc " << ntimes << " 次: 花费: " << free_costtime.load () << " ms\n " ;
75
- std::cout << nworks << " 个线程并发concurrent alloc&dealloc " << nworks * rounds * ntimes << " 次,总计花费: " << malloc_costtime.load () + free_costtime.load () << " ms\n " ;
73
+ std::cout << nworks << " threads run " << rounds << " times, each round malloc " << ntimes << " times, cost: " << malloc_costtime.load () << " ms\n " ;
74
+ std::cout << nworks << " threads run " << rounds << " times, each round free " << ntimes << " times, cost: " << free_costtime.load () << " ms\n " ;
75
+ std::cout << nworks << " threads run tcmalloc and tcfree " << nworks * rounds * ntimes << " time, total cost: " << malloc_costtime.load () + free_costtime.load () << " ms\n " ;
76
76
}
77
77
78
78
int main () {
79
79
size_t n = 1000 ;
80
- std::cout << " ==========================================================" << std::endl;
81
80
BenchmarkConcurrentMalloc (n, 4 , 10 );
82
- // std::cout << std::endl
83
- // << std::endl;
84
- // BenchmarkMalloc(n, 4, 10);
85
- std::cout << " ==========================================================" << std::endl;
81
+ std::cout << std::endl
82
+ << std::endl;
83
+ BenchmarkMalloc (n, 4 , 10 );
86
84
return 0 ;
87
85
}
0 commit comments