00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00051
00052 #include <benchs.h>
00053 #include <stddef.h>
00054 #include <string.h>
00055
00056
00057 int strcmp_for_bench (const char *s1, const char *s2);
00058 void bench_string (bench_t *b);
00059
00060
00061
00062
00063
00064
00065 char *
00066 strcpy (char * dest, const char *src)
00067 {
00068 char *tmp = dest;
00069
00070 while ((*dest++ = *src++) != '\0')
00071 ;
00072 return tmp;
00073 }
00074
00075 char *
00076 strcat (char *dest, const char *src)
00077 {
00078 char *tmp = dest;
00079
00080 while (*dest)
00081 dest++;
00082 while ((*dest++ = *src++) != '\0')
00083 ;
00084
00085 return tmp;
00086 }
00087
00088 int
00089 strcmp_for_bench (const char *cs, const char *ct)
00090 {
00091 register signed char __res;
00092
00093 while (1) {
00094 if ((__res = *cs - *ct++) != 0 || !*cs++)
00095 break;
00096 }
00097
00098 return __res;
00099 }
00100
00101 char *
00102 strrchr (const char *s, int c)
00103 {
00104 const char *p = s + strlen(s);
00105 do {
00106 if (*p == (char)c)
00107 return (char *)p;
00108 } while (--p >= s);
00109 return NULL;
00110 }
00111
00112 void *
00113 memcpy (void *dest, const void *src, size_t count)
00114 {
00115 char *tmp = (char *) dest, *s = (char *) src;
00116
00117 while (count--)
00118 *tmp++ = *s++;
00119
00120 return dest;
00121 }
00122
00123 int
00124 memcmp (const void *cs, const void * ct, size_t count)
00125 {
00126 const unsigned char *su1, *su2;
00127 signed char res = 0;
00128
00129 for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
00130 if ((res = *su1 - *su2) != 0)
00131 break;
00132 return res;
00133 }
00134
00135 char *
00136 strstr (const char * s1, const char * s2)
00137 {
00138 int l1, l2;
00139
00140 l2 = strlen(s2);
00141 if (!l2)
00142 return (char *) s1;
00143 l1 = strlen(s1);
00144 while (l1 >= l2) {
00145 l1--;
00146 if (!memcmp(s1,s2,l2))
00147 return (char *) s1;
00148 s1++;
00149 }
00150 return NULL;
00151 }
00152 #define MAX_LENGTH 64
00153
00154
00155 void
00156 bench_string (bench_t *b)
00157 {
00158 char buf[MAX_LENGTH];
00159 int res;
00160 char *p;
00161
00162
00163 bench_start (b);
00164 strcpy (buf, "0");
00165 bench_stop (b);
00166 bench_report (b, "strcpy length %d", (long) strlen (buf));
00167
00168 bench_start (b);
00169 strcpy (buf, "0123456789abcdef");
00170 bench_stop (b);
00171 bench_report (b, "strcpy length %d", (long) strlen (buf));
00172
00173 bench_start (b);
00174 strcpy (buf, "0123456789abcdef0123456789abcdef");
00175 bench_stop (b);
00176 bench_report (b, "strcpy length %d", (long) strlen (buf));
00177
00178 buf[0] = 0;
00179 bench_start (b);
00180 strcat (buf, "0");
00181 bench_stop (b);
00182 bench_report (b, "strcat length %d", (long) strlen (buf));
00183
00184 bench_start (b);
00185 strcat (buf, "0123456789abcdef");
00186 bench_stop (b);
00187 bench_report (b, "strcat length %d", (long) strlen (buf));
00188
00189 bench_start (b);
00190 strcat (buf, "0123456789abcdef");
00191 bench_stop (b);
00192 bench_report (b, "strcat length %d", (long) strlen (buf));
00193
00194 strcpy (buf, "0");
00195 bench_start (b);
00196 res = strlen (buf);
00197 bench_stop (b);
00198 bench_report (b, "strlen length %d", (long) res);
00199
00200 strcat (buf, "0123456789abcdef");
00201 bench_start (b);
00202 res = strlen (buf);
00203 bench_stop (b);
00204 bench_report (b, "strlen length %d", (long) res);
00205
00206 strcat (buf, "0123456789abcdef");
00207 bench_start (b);
00208 res = strlen (buf);
00209 bench_stop (b);
00210 bench_report (b, "strlen length %d", (long) res);
00211
00212 bench_start (b);
00213 res = strcmp_for_bench (buf, "0123456789abcdef0123456789abcdef");
00214 bench_stop (b);
00215 bench_report (b, "strcmp length %d, %d", (long) strlen (buf),
00216 (long) res);
00217
00218 bench_start (b);
00219 p = strrchr (buf, '0');
00220 bench_stop (b);
00221 bench_report (b, "strrchr at %d", (long) (size_t) (p - buf));
00222
00223 bench_start (b);
00224 p = strstr (buf, "f0123456789abcdef");
00225 bench_stop (b);
00226 bench_report (b, "strstr at %d", (long) (size_t) (p - buf));
00227
00228 }
00229
00230
00231 int
00232 main ()
00233 {
00234 bench_t b;
00235
00236 bench_init (&b);
00237 bench_string (&b);
00238 return 0;
00239 }
00240