lkml.org 
[lkml]   [1998]   [Apr]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectfaster strcpy()
For all those who are so sure of themselves:

Script started on Sun Apr 26 20:11:46 1998
# cat xxx.c
#include <stdio.h>
#include <string.h>
#include <signal.h>

#define LEN 0x1000

static char source[LEN];
static char destin[LEN];
int trg;
long count;

void stop(int unused)
{
printf("Count = %ld\n", count);
fflush(stdout);
trg = 0;
}
main()
{
int i;
memset(source, 0x20, LEN-1);
i = LEN - 1;
for(;;)
{
source[i] = (char) 0x00;
printf("Length = %d\n", i);
i -= 64;
if(i <=0 ) exit(0);
printf("Normal strcpy() ");
(void)signal(SIGALRM, stop);
trg = 1;
count = 0L;
alarm(1);
while(trg)
{
count++;
strcpy(destin, source);
}
printf("Strange strcpy() ");
(void)signal(SIGALRM, stop);
trg = 1;
count = 0L;
alarm(1);
while(trg)
{
count++;
memcpy(destin, source, strlen(source) + 1);
}
}
return 0;
}

# gcc -O2 -o xxx xxx.c
# xxx
Length = 4095
Normal strcpy() Count = 32504
Strange strcpy() Count = 15352
Length = 4031
Normal strcpy() Count = 32495
Strange strcpy() Count = 15733
Length = 3967
Normal strcpy() Count = 33089
Strange strcpy() Count = 15831
Length = 3903
Normal strcpy() Count = 33883
Strange strcpy() Count = 16072
Length = 3839
Normal strcpy() Count = 34473
Strange strcpy() Count = 16506
Length = 3775
Normal strcpy() Count = 34723

# echo Note that normal strcpy copies about twice as many strings in
Note that normal strcpy copies about twice as many strings in
# echo one second as does strlen + memcpy.
one second as does strlen + memcpy.
# cat /proc/cpuinfo
processor : 0
cpu family : 6
model : Pentium II (Klamath)
vendor_id : GenuineIntel
stepping : 3
fdiv_bug : no
hlt_bug : no
sep_bug : no
f00f_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov mmx
bogomips : 266.24

processor : 1
cpu family : 6
model : Pentium II (Klamath)
vendor_id : GenuineIntel
stepping : 3
fdiv_bug : no
hlt_bug : no
sep_bug : no
f00f_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov mmx
bogomips : 266.24

# exit
exit

Script done on Sun Apr 26 20:14:18 1998

The 'C' library is glibc-2.0.5. Case closed.


Cheers,
Dick Johnson
***** FILE SYSTEM MODIFIED *****
Penguin : Linux version 2.1.92 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu

\
 
 \ /
  Last update: 2005-03-22 13:42    [W:0.062 / U:0.692 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site