/*
* Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*
*/
/*
** Compile this program using a command line similar to:
** where "OBJ" is the name of the object directory for the platform
** you are compiling on.
** Then run the program:
** ./b-strl
** and read the output for results and how to interpret the results.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void
char *str;
{
exit(1);
}
void
purpose()
{
printf("This program benchmarks the performance differences between\n");
printf("strlcpy() and sm_strlcpy(), and strlcat() and sm_strlcat().\n");
printf("These tests may take several minutes to complete.\n");
}
int
int argc;
char *argv[];
{
#if !SM_CONF_STRL
printf("The configuration indicates the system needs the libsm\n");
printf("versions of strlcpy(3) and strlcat(3). Thus, performing\n");
printf("these tests will not be of much use.\n");
printf("If your OS has strlcpy(3) and strlcat(3) then set the macro\n");
#else /* !SM_CONF_STRL */
int ch;
long a;
bool doit = false;
# define OPTIONS "d"
{
switch ((char) ch)
{
case 'd':
doit = true;
break;
default:
break;
}
}
if (!doit)
{
purpose();
printf("If you want to run it, specify -d as option.\n");
return 0;
}
/*
** Let's place a small string at the head of dest for
** catenation to happen (it'll be ignored for the copy).
*/
/*
** Let's place a larger string into source for the catenation and
** the copy.
*/
" This is the longer string that will be used for catenation and copying for the the performace testing. The longer the string being catenated or copied the greater the difference in measureable performance\n",
SRC_SIZE - 1);
/* Run-time comments to the user */
purpose();
printf("\n");
printf("Test 1: strlcat() versus sm_strlcat()\n");
fatal("gettimeofday");
for (a = 0; a < loops; a++)
fatal("gettimeofday");
fatal("gettimeofday");
for (a = 0; a < loops; a++)
fatal("gettimeofday");
{
{
printf("\t\t** results too close: no decision\n");
}
else
{
printf("\t\t** results too close redoing test %ld times **\n",
loops);
goto redo_cat;
}
}
printf("\n");
printf("Test 2: strlcpy() versus sm_strlpy()\n");
fatal("gettimeofday");
for (a = 0; a < loops; a++)
fatal("gettimeofday");
fatal("gettimeofday");
for (a = 0; a < loops; a++)
fatal("gettimeofday");
{
{
printf("\t\t** results too close: no decision\n");
}
else
{
printf("\t\t** results too close redoing test %ld times **\n",
loops);
goto redo_cpy;
}
}
printf("\n\n");
printf("Interpreting the results:\n");
printf("\tFor differences larger than 2 seconds, the lower value is\n");
printf("\tbetter and that function should be used for performance\n");
printf("\treasons.\n\n");
printf("This program will re-run the tests when the difference is\n");
printf("less than 2 seconds.\n");
printf("The result will vary depending on the compiler optimization\n"); printf("level used. Compiling the sendmail libsm library with a\n");
printf("better optimization level can change the results.\n");
#endif /* !SM_CONF_STRL */
return 0;
}