calloc() implementation question
Olivier Langlois
olivier@trillion01.com
Fri Dec 13 14:44:00 GMT 2013
OndÅej
On Thu, 2013-12-12 at 19:41 +0100, OndÅej BÃlka wrote:
> To see how big is speedup/loss write a benchmark that compares variant
> with memset and one with inline expansion.
>
> void *
> calloc2 (size_t n)
> {
> return memset (malloc (n), 0, n);
> }
>
> void *
> calloc3 (size_t n)
> {
> void *x = malloc (n);
> if (n < 9 * 16)
> ...
> }
that was an amazing suggestion as it did allow me to have some new
insight in glibc malloc/calloc performance.
first, the manual unrolled memset did turned out to be faster than the
unconditionnal memset() call.
The other unexpected result was that malloc + memset() (calloc2()) is
always faster than the real calloc() for allocation size <= ~ 64KB.
that was unexpected as I tought that because calloc may skip the memset
step, it would be faster and at worse be on par with malloc + memset().
I did my tests on Linux kernel 3.12.4 on a
Intel(R) Atom(TM) CPU N455 @ 1.66GHz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: calloc_emul.c
Type: text/x-csrc
Size: 659 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20131213/cdec2163/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tst-calloc.c
Type: text/x-csrc
Size: 1113 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20131213/cdec2163/attachment-0001.bin>
More information about the Libc-alpha
mailing list