aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2019-04-02 12:02:24 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2019-04-02 12:02:24 +0200
commit3f0225c2dffc2c5cf6887cb93f44cf8a1dd888c3 (patch)
tree15347c1d827ba16709ffa118fe1d3fd09e0c4c2b
parent5bcc88fb9131884edd545af1f085c043cf34166a (diff)
downloadallocbench-3f0225c2dffc2c5cf6887cb93f44cf8a1dd888c3.tar.gz
allocbench-3f0225c2dffc2c5cf6887cb93f44cf8a1dd888c3.zip
add real simple realloc benchmark
-rw-r--r--src/benchmarks/realloc.py39
-rw-r--r--src/benchmarks/realloc/Makefile25
-rw-r--r--src/benchmarks/realloc/realloc.c14
3 files changed, 78 insertions, 0 deletions
diff --git a/src/benchmarks/realloc.py b/src/benchmarks/realloc.py
new file mode 100644
index 0000000..d39c7a0
--- /dev/null
+++ b/src/benchmarks/realloc.py
@@ -0,0 +1,39 @@
+import matplotlib.pyplot as plt
+
+from src.benchmark import Benchmark
+
+
+class Benchmark_Realloc(Benchmark):
+ def __init__(self):
+ self.name = "realloc"
+ self.descrition = """Realloc 100 times"""
+
+ self.cmd = "realloc"
+
+ self.args = {"oneshot": [1]}
+
+ self.requirements = ["realloc"]
+ super().__init__()
+
+ def summary(self):
+ # bar plot
+ allocators = self.results["allocators"]
+
+ for i, allocator in enumerate(allocators):
+ y_vals = []
+ for perm in self.iterate_args(args=self.results["args"]):
+ y_vals.append(self.results["mean"][allocator][perm]["task-clock"])
+ x_vals = [i * x for x in range(1, len(y_vals) + 1)]
+ plt.bar(x_vals, y_vals, width=0.7, label=allocator, align="center",
+ color=allocators[allocator]["color"])
+
+ plt.legend()
+ plt.ylabel("task-clock in ms")
+ plt.title("realloc micro bench")
+ plt.savefig(self.name + ".png")
+ plt.clf()
+
+ self.export_to_csv(datapoints=["task-clock"])
+
+
+realloc = Benchmark_Realloc()
diff --git a/src/benchmarks/realloc/Makefile b/src/benchmarks/realloc/Makefile
new file mode 100644
index 0000000..66b38ca
--- /dev/null
+++ b/src/benchmarks/realloc/Makefile
@@ -0,0 +1,25 @@
+OBJDIR ?= obj
+
+CC ?= gcc
+
+WARNFLAGS ?= -Wall -Wextra
+COMMONFLAGS ?= -fno-builtin -fPIC -DPIC -pthread
+OPTFLAGS ?= -O3 -DNDEBUG
+
+CFLAGS ?= $(OPTFLAGS) $(WARNFLAGS) $(COMMONFLAGS)
+
+LDFLAGS ?= -pthread -static-libgcc
+
+.PHONY = all clean
+
+all: $(OBJDIR)/realloc
+
+$(OBJDIR)/realloc: realloc.c | $(OBJDIR)
+ @echo compiling $@...
+ $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $<
+
+$(OBJDIR):
+ mkdir -p $@
+
+clean:
+ rm -rf $(OBJDIR)
diff --git a/src/benchmarks/realloc/realloc.c b/src/benchmarks/realloc/realloc.c
new file mode 100644
index 0000000..2eddc26
--- /dev/null
+++ b/src/benchmarks/realloc/realloc.c
@@ -0,0 +1,14 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+size_t* array;
+size_t steps = 1;
+int main() {
+ for (int i = 0; i < 100; i++) {
+ if ((array = realloc(array, sizeof(size_t) * steps * i)) == NULL) {
+ perror("realloc");
+ return 1;
+ }
+ }
+ return 0;
+}