]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add benchmark for fr_time
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 23 Sep 2022 14:01:10 +0000 (10:01 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 23 Sep 2022 14:01:29 +0000 (10:01 -0400)
src/lib/util/all.mk
src/lib/util/time_tests.c [new file with mode: 0644]
src/lib/util/time_tests.mk [new file with mode: 0644]

index dcda8e040a8beb93b443bf9ed70e2f03c56aff77..c7dfff9eac5cc01943fea8c3f2dc6f5d1e7ca50e 100644 (file)
@@ -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 (file)
index 0000000..158535e
--- /dev/null
@@ -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 <a.cudbardb@freeradius.org>
+ */
+#include <freeradius-devel/util/acutest.h>
+#include <freeradius-devel/util/acutest_helpers.h>
+#include <freeradius-devel/util/time.h>
+
+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 (file)
index 0000000..45fb820
--- /dev/null
@@ -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)