From: Arran Cudbard-Bell Date: Fri, 23 Sep 2022 14:01:10 +0000 (-0400) Subject: Add benchmark for fr_time X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d24326f248cae1e1686e3351d760a14f3ccdf34c;p=thirdparty%2Ffreeradius-server.git Add benchmark for fr_time --- diff --git a/src/lib/util/all.mk b/src/lib/util/all.mk index dcda8e040a8..c7dfff9eac5 100644 --- a/src/lib/util/all.mk +++ b/src/lib/util/all.mk @@ -15,5 +15,6 @@ SUBMAKEFILES := \ rb_tests.mk \ sbuff_tests.mk \ size_tests.mk \ - strerror_tests.mk + strerror_tests.mk \ + time_tests.mk diff --git a/src/lib/util/time_tests.c b/src/lib/util/time_tests.c new file mode 100644 index 00000000000..158535e0a45 --- /dev/null +++ b/src/lib/util/time_tests.c @@ -0,0 +1,53 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** Tests for a generic string buffer structure for string printing and parsing + * + * @file src/lib/util/time_tests.c + * + * @copyright 2022 Arran Cudbard-Bell + */ +#include +#include +#include + +static void time_benchmark(void) +{ + int i; + fr_time_t start, stop; + uint64_t rate; + + start = fr_time(); + for (i = 0; i < 100000; i++) { + fr_time_t now; + + (fr_time_t volatile)now = fr_time(); + } + stop = fr_time(); + + rate = (uint64_t)((float)NSEC / (fr_time_delta_unwrap(fr_time_sub(stop, start)) / 100000)); + printf("fr_time rate %" PRIu64 "\n", rate); + + /* shared runners are terrible for performance tests */ + if (!getenv("NO_PERFORMANCE_TESTS")) TEST_CHECK(rate > 1000000); +} + + +TEST_LIST = { + { "time_const_benchmark", time_benchmark }, + + { 0 } +}; diff --git a/src/lib/util/time_tests.mk b/src/lib/util/time_tests.mk new file mode 100644 index 00000000000..45fb820ede5 --- /dev/null +++ b/src/lib/util/time_tests.mk @@ -0,0 +1,6 @@ +TARGET := time_tests$(E) +SOURCES := time_tests.c + +TGT_LDLIBS := $(LIBS) $(GPERFTOOLS_LIBS) +TGT_LDFLAGS := $(LDFLAGS) $(GPERFTOOLS_LDFLAGS) +TGT_PREREQS := libfreeradius-util$(L)