Mercurial > hg > batmud > maputils
changeset 1897:38cc5e420118
Implement benchmarking.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 06 Nov 2017 03:54:49 +0200 |
parents | 36074f4e95c7 |
children | 9da7e7526bde |
files | mapsearch.c |
diffstat | 1 files changed, 39 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mapsearch.c Mon Nov 06 03:29:36 2017 +0200 +++ b/mapsearch.c Mon Nov 06 03:54:49 2017 +0200 @@ -93,6 +93,7 @@ int optUID = -1, optGID = -1; char *optLogFilename = NULL; FILE *setLogFH = NULL; +int optBenchmark = -1; unsigned char *setLWSBuffer = NULL; @@ -107,6 +108,7 @@ { 3, 0, "ssl-ciphers", "Specify list of SSL/TLS ciphers", OPT_ARGREQ }, { 5, 'w', "world-origin", "Specify the world origin <x:y> which map offsets relate to", OPT_ARGREQ }, { 6, 'T', "test", "Test search with given file input", OPT_ARGREQ }, + { 4, 'B', "benchmark", "Run a benchmark on test input (-T option) of <n> cycles", OPT_ARGREQ }, { 7, 'U', "uid", "Run as UID", OPT_ARGREQ }, { 8, 'G', "gid", "Run as GID", OPT_ARGREQ }, { 9, 'L', "log-file", "Log to specified file", OPT_ARGREQ }, @@ -486,6 +488,18 @@ optTest = optArg; break; + case 4: + { + int tmp = atoi(optArg); + if (tmp < 10) + { + THERR("Invalid bechmark cycle count %d.\n", optBenchmark); + return FALSE; + } + optBenchmark = tmp; + } + break; + case 7: if (sscanf(optArg, "%d", &optUID) != 1) { @@ -1366,9 +1380,31 @@ if (mapReadFile(optTest, &buf, &bufSize) == 0) { char *verr = NULL; - mapPerformSearch(NULL, buf, bufSize, &verr); - if (verr != NULL) - THERR("%s\n", verr); + if (optBenchmark > 0) + { + int save = th_verbosityLevel; + THMSG(0, "Benchmarking for %d cycles ..\n", optBenchmark); + th_verbosityLevel = -1; + for (int n = 0; n < optBenchmark; n++) + { + printf("."); + fflush(stdout); + mapPerformSearch(NULL, buf, bufSize, &verr); + if (verr != NULL) + { + THERR("%s\n", verr); + break; + } + } + th_verbosityLevel = save; + THMSG(0, "Finished. Took ...\n"); + } + else + { + mapPerformSearch(NULL, buf, bufSize, &verr); + if (verr != NULL) + THERR("%s\n", verr); + } } else THERR("Could not read test file.\n");