This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
RE: [PATCH] Improve performance of strncpy
- From: "Wilco Dijkstra" <wdijkstr at arm dot com>
- To: 'Ondřej Bílka' <neleai at seznam dot cz>
- Cc: <azanella at linux dot vnet dot ibm dot com>, <libc-alpha at sourceware dot org>
- Date: Thu, 27 Nov 2014 19:20:43 -0000
- Subject: RE: [PATCH] Improve performance of strncpy
- Authentication-results: sourceware.org; auth=none
- References: <001a01cfefa3$0fb21330$2f163990$ at com> <20141123165227 dot GA27543 at domone>
> Ondřej Bílka wrote:
> On Fri, Oct 24, 2014 at 04:56:23PM +0100, Wilco Dijkstra wrote:
> > Ping (there was some further discussion but I don't see an OK for this patch)
> >
> Looks ok, any reason why not simplify it more to strnlen+memcpy+memset?
Well that is possible too. I benchmarked this and it is 1.7x on x64, and 2x
on AArch64 (compared to my patch). However it does seem to be mostly due to
the large strings, small strings are slower as you can see below. I don't
believe that bench-strncpy is a good benchmark as it only seems to test strings
of 0.5x, 1.0x and 2.0x the buffer size (none of which would be common in the
real world), do you happen to know a better strncpy benchmark?
strncpy_orig strncpy
Length 16, n 16, alignment 1/ 1: 31.1694 60.0666
Length 16, n 16, alignment 1/ 1: 36.8311 60.0364
Length 16, n 16, alignment 1/ 2: 35.9034 60.0394
Length 16, n 16, alignment 2/ 1: 37.768 60.0356
Length 2, n 4, alignment 7/ 2: 60.9953 75.4958
Length 4, n 2, alignment 2/ 7: 19.6473 57.3082
Length 2, n 4, alignment 7/ 2: 57.9887 75.4963
Length 4, n 2, alignment 2/ 7: 21.8327 57.3139
...
Length 256, n 512, alignment 0/ 0: 423.878 193.744
Length 1024, n 512, alignment 0/ 0: 729.506 262.873
Length 256, n 512, alignment 2/ 4: 423.877 207.391
Length 1024, n 512, alignment 2/ 4: 728.664 273.792
Length 512, n 1024, alignment 0/ 0: 796.739 315.629
Length 2048, n 1024, alignment 0/ 0: 1425.05 479.289
Length 512, n 1024, alignment 1/ 6: 791.347 333.821
Length 2048, n 1024, alignment 1/ 6: 1428.08 493.005