@@ -35,9 +35,9 @@ void BenchmarkMalloc(size_t ntimes, size_t nworks, size_t rounds) {
3535 for (auto & t : vthread) {
3636 t.join ();
3737 }
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 " ;
4141}
4242
4343// 单轮次申请释放次数 线程数 轮次
@@ -70,18 +70,16 @@ void BenchmarkConcurrentMalloc(size_t ntimes, size_t nworks, size_t rounds) {
7070 for (auto & t : vthread) {
7171 t.join ();
7272 }
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 " ;
7676}
7777
7878int main () {
7979 size_t n = 1000 ;
80- std::cout << " ==========================================================" << std::endl;
8180 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 );
8684 return 0 ;
8785}
0 commit comments