MCPcopy Create free account
hub / github.com/apache/brpc / new_and_delete_int

Function new_and_delete_int

test/resource_pool_unittest.cpp:337–371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

335}
336
337void* new_and_delete_int(void*) {
338 const size_t N = 100000;
339 std::vector<D*> v2;
340 v2.reserve(N);
341 butil::Timer tm0, tm1, tm2;
342 D tmp = D();
343
344 for (int j = 0; j < 3; ++j) {
345 v2.clear();
346
347 // warm up
348 delete (new D);
349
350 tm1.start();
351 for (size_t i = 0; i < N; ++i) {
352 D *p = new D;
353 *p = tmp;
354 v2.push_back(p);
355 }
356 tm1.stop();
357
358 std::random_shuffle(v2.begin(), v2.end());
359
360 tm2.start();
361 for (size_t i = 0; i < v2.size(); ++i) {
362 delete v2[i];
363 }
364 tm2.stop();
365
366 printf("[%lu:%d] new<D>=%.1f delete<D>=%.1f\n",
367 pthread_self(), j, tm1.n_elapsed()/(double)N, tm2.n_elapsed()/(double)N);
368 }
369
370 return NULL;
371}
372
373TEST_F(ResourcePoolTest, get_and_return_int_single_thread) {
374 get_and_return_int(NULL);

Callers 1

TEST_FFunction · 0.70

Calls 10

n_elapsedMethod · 0.80
DClass · 0.70
reserveMethod · 0.45
clearMethod · 0.45
startMethod · 0.45
push_backMethod · 0.45
stopMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected