X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftal%2Fbenchmark%2Fsamba-allocs.c;h=e25c7e9b69163996c96ad22081307ad24b729355;hb=8f116a81b39b55031212abb0be2ad088cbf9fd87;hp=074276d8cdcbe5368fc564b4276811d07135bb1c;hpb=5e0d0dcb720ebbc4998871c63dfd47c00bca11ba;p=ccan diff --git a/ccan/tal/benchmark/samba-allocs.c b/ccan/tal/benchmark/samba-allocs.c index 074276d8..e25c7e9b 100644 --- a/ccan/tal/benchmark/samba-allocs.c +++ b/ccan/tal/benchmark/samba-allocs.c @@ -141,8 +141,14 @@ static int unused_talloc_destructor(void *p) static void do_tallocs(struct node *node) { unsigned int i; - - node->n = talloc_size(node->parent ? node->parent->n : NULL, node->len); + static int count; + + if (count++ % 16 == 0) + node->n = talloc_array(node->parent ? node->parent->n : NULL, + char, node->len); + else + node->n = talloc_size(node->parent ? node->parent->n : NULL, + node->len); if (node->destructor) talloc_set_destructor(node->n, unused_talloc_destructor); if (node->name) @@ -169,9 +175,18 @@ static void unused_tal_destructor(void *p) static void do_tals(struct node *node) { unsigned int i; + static int count; + + /* Tal pays a penalty for arrays, but we can't tell which is an array + * and which isn't. Grepping samba source gives 1221 talloc_array of + * 33137 talloc occurrences, so conservatively assume 1 in 16 */ + if (count++ % 16 == 0) + node->n = tal_arr(node->parent ? node->parent->n : NULL, + char, node->len); + else + node->n = tal_alloc_(node->parent ? node->parent->n : NULL, + node->len, false, TAL_LABEL(type, "")); - node->n = tal_arr(node->parent ? node->parent->n : NULL, - char, node->len); if (node->destructor) tal_add_destructor(node->n, unused_tal_destructor); if (node->name) @@ -340,7 +355,6 @@ after_talloc: printf("Tal time: %lluns\n", time_to_nsec(alloc_time)); printf("Tal_free time: %lluns\n", time_to_nsec(free_time)); -after_tal: free_time.tv_sec = free_time.tv_nsec = 0; for (i = 0; i < LOOPS; i++) { do_tals(root); @@ -351,6 +365,7 @@ after_tal: } free_time = time_divide(free_time, i); printf("Single tal_free time: %lluns\n", time_to_nsec(free_time)); +after_tal: return 0; }