From e8a35c4b691d1b6eb12e934dffd20d75201fa5c8 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Tue, 11 Nov 2008 13:37:53 +0100 Subject: [PATCH] Compare query_format and snprintf performances. Signed-off-by: Florent Bruneau --- postlicyd/tst-qf.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/postlicyd/tst-qf.c b/postlicyd/tst-qf.c index 1d8343b..780f89b 100644 --- a/postlicyd/tst-qf.c +++ b/postlicyd/tst-qf.c @@ -88,18 +88,30 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - static const char *format = "${sender} ${recipient} and ${client_name}[${client_address}] at ${protocol_state}"; - - time_t now = time(0); - - char str[BUFSIZ]; - static const int iterations = 10000000; - for (int i = 0 ; i < iterations ; ++i) { - query_format(str, BUFSIZ, format, &q); + static const int iterations = 50000000; + { + static const char *format = "${sender} ${recipient} and ${client_name}[${client_address}] at ${protocol_state}"; + time_t now = time(0); + char str[BUFSIZ]; + for (int i = 0 ; i < iterations ; ++i) { + query_format(str, BUFSIZ, format, &q); + } + time_t ellapsed = time(0) - now; + printf("Done %d iterations in %us (%d format per second)\n", iterations, + (uint32_t)ellapsed, (int)(iterations / ellapsed)); } - time_t ellapsed = time(0) - now; - printf("Done %d iterations in %us (%d format per second)\n", iterations, - (uint32_t)ellapsed, (int)(iterations / ellapsed)); + { + time_t now = time(0); + char str[BUFSIZ]; + for (int i = 0 ; i < iterations ; ++i) { + snprintf(str, BUFSIZ, "%s %s and %s[%s] at %s", + q.sender.str, q.recipient.str, q.client_name.str, q.client_address.str, + smtp_state_names[q.state].str); + } + time_t ellapsed = time(0) - now; + printf("Done %d iterations in %us (%d format per second)\n", iterations, + (uint32_t)ellapsed, (int)(iterations / ellapsed)); + } return 0; } -- 2.20.1