2 * Copyright (c) 2000-2001, 2004 Sendmail, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
11 SM_RCSID("@(#)$Id: b-strcmp.c,v 1.14 2005/06/14 23:07:20 ca Exp $")
15 #include <sys/types.h>
17 #include <sm/string.h>
19 #define toseconds(x, y) (x.tv_sec - y.tv_sec)
21 #define LOOPS 4000000L /* initial number of loops */
22 #define MAXTIME 30L /* "maximum" time to run single test */
24 void fatal
__P((char *));
25 void purpose
__P((void));
26 int main
__P((int, char *[]));
39 printf("This program benchmarks the performance differences between\n");
40 printf("strcasecmp() and sm_strcasecmp().\n");
41 printf("These tests may take several minutes to complete.\n");
55 struct timeval t1
, t2
;
56 char src1
[SIZE
], src2
[SIZE
];
59 while ((k
= getopt(argc
, argv
, OPTIONS
)) != -1)
75 printf("If you want to run it, specify -d as option.\n");
79 /* Run-time comments to the user */
82 for (k
= 0; k
< 3; k
++)
87 (void) sm_strlcpy(src1
, "1234567890", SIZE
);
88 (void) sm_strlcpy(src2
, "1234567890", SIZE
);
91 (void) sm_strlcpy(src1
, "1234567890", SIZE
);
92 (void) sm_strlcpy(src2
, "1234567891", SIZE
);
95 (void) sm_strlcpy(src1
, "1234567892", SIZE
);
96 (void) sm_strlcpy(src2
, "1234567891", SIZE
);
99 printf("Test %d: strcasecmp(%s, %s) versus sm_strcasecmp()\n",
105 if (gettimeofday(&t1
, NULL
) < 0)
106 fatal("gettimeofday");
107 for (a
= 0; a
< loops
; a
++)
108 j
+= strcasecmp(src1
, src2
);
109 if (gettimeofday(&t2
, NULL
) < 0)
110 fatal("gettimeofday");
111 one
= toseconds(t2
, t1
);
112 printf("\tstrcasecmp() result: %ld seconds [%ld]\n",
116 if (gettimeofday(&t1
, NULL
) < 0)
117 fatal("gettimeofday");
118 for (a
= 0; a
< loops
; a
++)
119 j
+= sm_strcasecmp(src1
, src2
);
120 if (gettimeofday(&t2
, NULL
) < 0)
121 fatal("gettimeofday");
122 two
= toseconds(t2
, t1
);
123 printf("\tsm_strcasecmp() result: %ld seconds [%ld]\n",
126 if (abs(one
- two
) > 2)
129 if (loops
< 0L || one
> MAXTIME
)
131 printf("\t\t** results too close: no decision\n");
136 printf("\t\t** results too close redoing test %ld times **\n",
143 printf("Interpreting the results:\n");
144 printf("\tFor differences larger than 2 seconds, the lower value is\n");
145 printf("\tbetter and that function should be used for performance\n");
146 printf("\treasons.\n\n");
147 printf("This program will re-run the tests when the difference is\n");
148 printf("less than 2 seconds.\n");
149 printf("The result will vary depending on the compiler optimization\n"); printf("level used. Compiling the sendmail libsm library with a\n");
150 printf("better optimization level can change the results.\n");