diff options
Diffstat (limited to 'src/benchmarks/realloc')
| -rw-r--r-- | src/benchmarks/realloc/Makefile | 25 | ||||
| -rw-r--r-- | src/benchmarks/realloc/realloc.c | 14 |
2 files changed, 39 insertions, 0 deletions
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; +} |
