This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Simple malloc benchtest.
- From: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: OndÅej BÃlka <neleai at seznam dot cz>
- Cc: libc-alpha at sourceware dot org
- Date: Mon, 23 Dec 2013 14:36:27 +0530
- Subject: Re: [PATCH] Simple malloc benchtest.
- Authentication-results: sourceware.org; auth=none
- References: <20131221153303 dot GA8420 at domone dot podge>
On Sat, Dec 21, 2013 at 04:33:03PM +0100, OndÅej BÃlka wrote:
> +void
> +do_test (size_t size)
> +{
> + timing_t start, stop, cur;
> + const int iters = 1<<18;
> +
> + unsigned int r_seed = 42;
> + void *ary[iters];
> + size_t sizes[iters];
> + size_t idx[iters];
> +
> + for (int i = 0; i < iters; i++)
> + {
> + ary[i] = NULL;
> + sizes[i] = size + rand_r (&r_seed) % (7 * size);
> + idx[i] = rand_r (&r_seed) % (iters / 64);
> + }
> +
> + printf ("\n allocations in range %lu-%lu:", size, 8 * size);
> +
> + TIMING_NOW (start);
> +
> + for (int i = 0; i < iters; ++i)
> + {
> + free (ary[idx[i]]);
> + ary[idx[i]] = malloc (sizes[i]);
> + }
> +
> + for (int i = 0; i < iters; ++i)
> + free (ary[i]);
> +
> + TIMING_NOW (stop);
> + TIMING_DIFF (cur, start, stop);
> + TIMING_PRINT_MEAN ((double) cur, (double) iters);
In addition to Wills concerns, I'd also like to see a simple
evaluation of fragmentation resulting from a sequence of allocations
and frees. To get that you'll need to keep some blocks un-freed -
choosing those blocks would be another interesting problem.
Siddhesh