X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftal%2Fbenchmark%2Fspeed.c;fp=ccan%2Ftal%2Fbenchmark%2Fspeed.c;h=0b4815fed4b82598fca562072f6df14a9c338f4e;hp=0000000000000000000000000000000000000000;hb=de8e8cf2e214b880e14b20817e665477a5dc5bdb;hpb=da9f271b74088191908e69f01acfbe05c390a87f
diff --git a/ccan/tal/benchmark/speed.c b/ccan/tal/benchmark/speed.c
new file mode 100644
index 00000000..0b4815fe
--- /dev/null
+++ b/ccan/tal/benchmark/speed.c
@@ -0,0 +1,124 @@
+/*
+ Taken from samba/lib/talloc/testsuite.c: Unix SMB/CIFS implementation.
+
+ local testing of talloc routines.
+
+ Copyright (C) Andrew Tridgell 2004
+
+ ** NOTE! The following LGPL license applies to the talloc
+ ** library. This does NOT imply that all of Samba is released
+ ** under the LGPL
+
+ 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 3 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, see .
+*/
+#include
+#include
+#include
+#include
+#include
+
+#define LOOPS 1024
+
+int main(int argc, char *argv[])
+{
+ void *ctx;
+ unsigned count;
+ int i, j;
+ struct timespec tv;
+ void *p1, *p2[100], *p3[100];
+ bool run_talloc = true, run_tal = true, run_malloc = true;
+
+ if (argv[1]) {
+ if (strcmp(argv[1], "--talloc") == 0)
+ run_tal = run_malloc = false;
+ else if (strcmp(argv[1], "--tal") == 0)
+ run_talloc = run_malloc = false;
+ else if (strcmp(argv[1], "--malloc") == 0)
+ run_talloc = run_tal = false;
+ else
+ errx(1, "Bad flag %s", argv[1]);
+ }
+
+ if (!run_talloc)
+ goto after_talloc;
+
+ ctx = talloc_new(NULL);
+ tv = time_now();
+ count = 0;
+ do {
+ for (i=0;i