[Bug string/26091] strcpy cost more time in glibc-2.31
guojinhui at huawei dot com
sourceware-bugzilla@sourceware.org
Mon Jun 8 02:06:02 GMT 2020
https://sourceware.org/bugzilla/show_bug.cgi?id=26091
--- Comment #2 from JinhuiGuo <guojinhui at huawei dot com> ---
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <string.h>
int s = 10;
int unaligned = 0;
void init_str(char *str)
{
static char *demo =
"The quick brown fox jumps over the lazy dog.";
int l = strlen(demo);
int i;
for (i = 0; i < s; i++) {
str[i] = demo[i % l];
}
str[s] = 0;
}
int main(void)
{
int i;
struct timespec tv;
struct timespec tv1;
char *src2 = (char *)malloc(s + 1);
char *src = (char *)malloc(s + 1 + unaligned);
init_str(src2);
src2 += unaligned;
clock_gettime(CLOCK_MONOTONIC, &tv);
for (i = 0; i < 1100000; i += 10) {
(void) strcpy(src, src2);
(void) strcpy(src, src2);
(void) strcpy(src, src2);
(void) strcpy(src, src2);
(void) strcpy(src, src2);
(void) strcpy(src, src2);
(void) strcpy(src, src2);
(void) strcpy(src, src2);
(void) strcpy(src, src2);
(void) strcpy(src, src2);
}
clock_gettime(CLOCK_MONOTONIC, &tv1);
long long tmp = ((long long)tv1.tv_sec * 1000000000LL) - ((long
long)tv.tv_sec * 1000000000LL) + ((long long)tv1.tv_nsec ) - ((long
long)tv.tv_nsec);
printf("cost: %f ns\n", ((double)tmp) / i);
src2 -= unaligned;
free(src);
free(src2);
return 0;
}
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the Glibc-bugs
mailing list