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