From 5137f8721b71234c242baa0d6379a487811119b9 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Tue, 14 Jun 2011 13:35:44 +0400 Subject: [PATCH] zalloc_ext_test added --- c/zalloc_ext/Makefile | 71 ++++++++++++++++++++++++++++++++++ c/zalloc_ext/zalloc_ext.geany | 47 ++++++++++++++++++++++ c/zalloc_ext/zalloc_ext_test.c | 47 ++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 c/zalloc_ext/Makefile create mode 100644 c/zalloc_ext/zalloc_ext.geany create mode 100644 c/zalloc_ext/zalloc_ext_test.c diff --git a/c/zalloc_ext/Makefile b/c/zalloc_ext/Makefile new file mode 100644 index 0000000..92c666d --- /dev/null +++ b/c/zalloc_ext/Makefile @@ -0,0 +1,71 @@ +CC=cc +CXX=c++ +INCLUDE=-I$(HOME)/projects/include +KOLAN_PROJECTS=$(HOME)/projects +KOLAN_INCLUDE=$(KOLAN_PROJECTS)/include + +# Compiler flags +# if mode variable is empty, setting debug build mode +ifeq ($(mode),) + mode = debug +endif +ifeq ($(mode),debug) + CFLAGS = -O0 -g -std=gnu99 -pedantic -Wextra -Wconversion + LDFLAGS = +endif +ifeq ($(mode),profile) + CFLAGS = -O0 -g -p -ftest-coverage -Wcoverage-mismatch + LDFLAGS = -g -p +endif +ifeq ($(mode),develop) + CFLAGS += -O2 -g + LDFLAGS += -O1 +endif +ifeq ($(mode),release) + CFLAGS += -O2 + LDFLAGS += -O1 +endif + +CFLAGS += -Wall +#~ $(shell pkg-config --cflags liblist) +LDFLAGS += -Wall +#~ $(shell pkg-config --libs liblist) + +all: zalloc_ext_test + +ifneq ($(mode),debug) +ifneq ($(mode),profile) +ifneq ($(mode),develop) +ifneq ($(mode),release) + @echo "Invalid build mode." + @echo "Please use 'make mode=release' or 'make mode=develop' or 'make mode=debug'" + @exit 1 +endif +endif +endif +endif + @echo ".........................." + @echo "Building on "$(mode)" mode " + @echo "CFLAGS=$(CFLAGS)" + @echo "LDFLAGS=$(LDFLAGS)" + @echo ".........................." + +%.o : + $(CC) -c $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o $@ $< + +zalloc_ext_test_obj = zalloc_ext.o zalloc.o xerror.o +zalloc_ext_test: zalloc_ext_test.o $(zalloc_ext_test_obj) + $(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o $@ zalloc_ext_test.o $(zalloc_ext_test_obj) + +zalloc_ext_test.o: zalloc_ext_test.c zalloc_ext.o zalloc.o + +zalloc_ext.o: $(KOLAN_INCLUDE)/zalloc_ext.c $(KOLAN_INCLUDE)/zalloc_ext.h + +zalloc.o: $(KOLAN_INCLUDE)/zalloc.c $(KOLAN_INCLUDE)/zalloc.h + +xerror.o: $(KOLAN_INCLUDE)/xerror.c $(KOLAN_INCLUDE)/xerror.c + +clean: + $(RM) *.o *.out callgrind.out.* *.gcno zalloc_ext_test + +.PHONY: all clean diff --git a/c/zalloc_ext/zalloc_ext.geany b/c/zalloc_ext/zalloc_ext.geany new file mode 100644 index 0000000..e06bb92 --- /dev/null +++ b/c/zalloc_ext/zalloc_ext.geany @@ -0,0 +1,47 @@ + +[indentation] +indent_width=8 +indent_type=1 +indent_hard_tab_width=8 +detect_indent=false +indent_mode=2 + +[project] +name=zalloc_ext_test +base_path=/home/kolan/dev/c/zalloc_ext/ +description= + +[long line marker] +long_line_behaviour=1 +long_line_column=72 + +[files] +current_page=0 +FILE_NAME_0=0;C;0;16;1;1;1;/home/kolan/dev/c/zalloc_ext/zalloc_test.c;0 +FILE_NAME_1=1670;Make;0;16;1;1;1;/home/kolan/dev/c/zalloc_ext/Makefile;0 +FILE_NAME_2=0;C;0;16;1;1;1;/home/kolan/projects/include/zalloc_ext.c;0 +FILE_NAME_3=926;C;0;16;1;1;1;/home/kolan/projects/include/zalloc_ext.h;0 + +[build-menu] +NF_00_LB=_Сделать +NF_00_CM=make +NF_00_WD=%p +NF_01_LB=Сделать заданную _цель +NF_01_CM=make +NF_01_WD=%p +NF_02_LB=Сделать _объект +NF_02_CM=make %e.o +NF_02_WD=%p +EX_00_LB=_Выполнить +EX_00_CM=./%e +EX_00_WD=%p +MakeFT_00_LB= +MakeFT_00_CM= +MakeFT_00_WD=%p +MakeFT_01_LB= +MakeFT_01_CM= +MakeFT_01_WD=%p +MakeFT_02_LB= +MakeFT_02_CM= +MakeFT_02_WD=%p +filetypes=Make; diff --git a/c/zalloc_ext/zalloc_ext_test.c b/c/zalloc_ext/zalloc_ext_test.c new file mode 100644 index 0000000..07d82f9 --- /dev/null +++ b/c/zalloc_ext/zalloc_ext_test.c @@ -0,0 +1,47 @@ +//~ kolan@nickolay-842 ~/dev/c/zalloc(default) $ time ./zalloc_test 50000 100000 +//~ Success, iterations = 50000, nobj = 100000 +//~ +//~ real 0m0.246s +//~ user 0m0.110s +//~ sys 0m0.130s + +#include +#include +#include + +#include "zalloc.h" + +int main(int argc, char *argv[]) +{ + if (argc != 3) { + fputs("Usage: realloc_speed_test_cpp iterations nobj\n", stderr); + exit(-1); + } + + size_t iterations = (size_t)atoi(argv[1]); + size_t nobj = (size_t)atoi(argv[2]); + + void **p = zmalloc(sizeof(void *) * nobj); + memset(p, 0, sizeof(void *) * nobj); + + size_t i, idx, sz; + for (i = 0; i < iterations; i++) { + idx = (size_t)(rand() % (int)nobj); + sz = i; + p[idx] = zrealloc(p[idx], sz); + + if (sz && !p[idx]) { + fprintf(stderr, "Alloc error at i = %lu\n", i); + exit(-1); + } + } + + for (i = 0; i < nobj; i++) { + zfree(p[i]); + p[i] = NULL; + } + + printf("Success, iterations = %lu, nobj = %lu\n", iterations, nobj); + + return EXIT_SUCCESS; +}