zalloc vs std::string tests

This commit is contained in:
Kolan Sh 2011-07-17 21:41:45 +04:00
parent 4c45d76996
commit d1a92a7a7d
3 changed files with 55 additions and 24 deletions

View File

@ -35,6 +35,7 @@ int main(int argc, char *argv[])
sz = i; sz = i;
try { try {
v[idx].resize(sz); v[idx].resize(sz);
} catch(...) { } catch(...) {
fprintf(stderr, "Alloc error at i = %lu\n", i); fprintf(stderr, "Alloc error at i = %lu\n", i);
exit(-1); exit(-1);

View File

@ -10,6 +10,7 @@
#include <string.h> #include <string.h>
#include "zalloc.h" #include "zalloc.h"
#include "zalloc_ext.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -28,7 +29,7 @@ int main(int argc, char *argv[])
for (i = 0; i < iterations; i++) { for (i = 0; i < iterations; i++) {
idx = (size_t)(rand() % (int)nobj); idx = (size_t)(rand() % (int)nobj);
sz = i; sz = i;
zrealloc_inplace(&p[idx], sz); p[idx] = zrealloc(p[idx], sz);//zrealloc_inplace(&p[idx], sz);
if (sz && !p[idx]) { if (sz && !p[idx]) {
fprintf(stderr, "Alloc error at i = %lu\n", i); fprintf(stderr, "Alloc error at i = %lu\n", i);

View File

@ -4,8 +4,10 @@
# No need to call make clean if You make with other mode, # No need to call make clean if You make with other mode,
# because the Makefile containes rules for automatically clean. # because the Makefile containes rules for automatically clean.
# Some usage examples: # Some usage examples:
# CFLAGS="-march=core2 -mtune=core2" make # make # default mode is debug
# LDFLAGS="-lexpat" make mode=profile # CFLAGS="-O2 -march=core2 -mtune=core2 --msse4.1 mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,-ass-needed" make mode=develop
# CFLAGS="-O2 -march=amdfam10 -mtune=amdfam10 -msse4a --mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,--as-needed" make mode=profile
# CFLAGS="-O2 -march=k6-2 -mtune=k6-2 -m3dnow --mfpmath=387 -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,--as-needed" make mode=release
# Report bugs to <mecareful@gmail.com> # Report bugs to <mecareful@gmail.com>
#_________________________________ #_________________________________
@ -13,9 +15,11 @@
#________________________________| #________________________________|
CC=cc CC=cc
CXX=c++ CXX=c++
LIBRARIES= LIBRARIES=-lstdc++
TARGET0=zalloc_ext_test TARGET0=std_string_speed_test
TARGET= $(TARGET0) TARGET1=zalloc_speed_test_c
TARGET2=zalloc_ext_test
TARGET= $(TARGET0) $(TARGET1) $(TARGET2)
INCLUDE1=$(HOME)/projects/include INCLUDE1=$(HOME)/projects/include
INCLUDE2=/usr/local/include INCLUDE2=/usr/local/include
INCLUDE=-I$(INCLUDE1) -I$(INCLUDE2) INCLUDE=-I$(INCLUDE1) -I$(INCLUDE2)
@ -27,20 +31,20 @@ ifeq ($(mode),)
mode = debug mode = debug
endif endif
ifeq ($(mode),debug) ifeq ($(mode),debug)
CFLAGS = -O0 -g -std=gnu99 -pedantic -Wextra -Wconversion CFLAGS := -O0 -g -std=gnu99 -pedantic -Wextra -Wconversion $(CFLAGS)
LDFLAGS = LDFLAGS := $(LDFLAGS)
endif endif
ifeq ($(mode),profile) ifeq ($(mode),profile)
CFLAGS = -O0 -g -p -ftest-coverage -Wcoverage-mismatch CFLAGS := -O0 -g -p -ftest-coverage -Wcoverage-mismatch $(CFLAGS)
LDFLAGS = -g -p LDFLAGS := -g -p $(LDFLAGS)
endif endif
ifeq ($(mode),develop) ifeq ($(mode),develop)
CFLAGS += -O2 -g CFLAGS := -O2 -g $(CFLAGS)
LDFLAGS += -O1 LDFLAGS := -O1 $(LDFLAGS)
endif endif
ifeq ($(mode),release) ifeq ($(mode),release)
CFLAGS += -O2 CFLAGS := -O2 $(CFLAGS)
LDFLAGS += -O1 LDFLAGS := -O1 $(LDFLAGS)
endif endif
CFLAGS += -Wall CFLAGS += -Wall
@ -72,9 +76,9 @@ change_make_options:
ifneq ($(mode)|$(CFLAGS)|$(LDFLAGS), $(OLD_BUILD_MODE)|$(OLD_BUILD_CFLAGS)|$(OLD_BUILD_LDFLAGS)) ifneq ($(mode)|$(CFLAGS)|$(LDFLAGS), $(OLD_BUILD_MODE)|$(OLD_BUILD_CFLAGS)|$(OLD_BUILD_LDFLAGS))
@echo CLEANING... @echo CLEANING...
@make clean &>/dev/null @make clean &>/dev/null
@echo MODE=$(mode) > make_options.out @echo "MODE=$(mode)" > make_options.out
@echo CFLAGS=$(CFLAGS) >> make_options.out @echo "CFLAGS=$(CFLAGS)" >> make_options.out
@echo LDFLAGS=$(LDFLAGS) >> make_options.out @echo "LDFLAGS=$(LDFLAGS)" >> make_options.out
endif endif
%.o : %.o :
@ -89,27 +93,47 @@ clean:
# R U L E S | # R U L E S |
#________________________________| #________________________________|
target_objs0 = \ target_objs0 = \
std_string_speed_test.o
$(TARGET0): $(target_objs0)
$(CC) $(LDFLAGS) -o $@ $(target_objs0)
target_objs1 = \
zalloc_speed_test_c.o \
xerror.o \
zalloc.o \
zalloc_ext.o
$(TARGET1): $(target_objs1)
$(CC) $(LDFLAGS) -o $@ $(target_objs1)
target_objs2 = \
zalloc_ext_test.o \ zalloc_ext_test.o \
xalloc.o \ xalloc.o \
xerror.o \ xerror.o \
zalloc.o \ zalloc.o \
zalloc_ext.o zalloc_ext.o
$(TARGET0): $(target_objs0) $(TARGET2): $(target_objs2)
$(CC) $(LDFLAGS) -o $@ $(target_objs0) $(CC) $(LDFLAGS) -o $@ $(target_objs2)
std_string_speed_test.o: \
std_string_speed_test.cpp
zalloc_speed_test_c.o: \
zalloc_speed_test_c.c \
$(INCLUDE1)/zalloc.h \
$(INCLUDE1)/zalloc_ext.h
zalloc_ext_test.o: \ zalloc_ext_test.o: \
zalloc_ext_test.c \ zalloc_ext_test.c \
$(INCLUDE1)/xalloc.h \ $(INCLUDE1)/xalloc.h \
$(INCLUDE1)/zalloc.h \ $(INCLUDE1)/zalloc.h \
$(INCLUDE1)/zalloc_ext.h $(INCLUDE1)/zalloc_ext.h
xalloc.o: \
$(INCLUDE1)/xalloc.c \
$(INCLUDE1)/xalloc.h \
$(INCLUDE1)/xerror.h
zalloc.o: \ zalloc.o: \
$(INCLUDE1)/zalloc.c \ $(INCLUDE1)/zalloc.c \
$(INCLUDE1)/xerror.h \ $(INCLUDE1)/xerror.h \
@ -120,6 +144,11 @@ zalloc_ext.o: \
$(INCLUDE1)/zalloc.h \ $(INCLUDE1)/zalloc.h \
$(INCLUDE1)/zalloc_ext.h $(INCLUDE1)/zalloc_ext.h
xalloc.o: \
$(INCLUDE1)/xalloc.c \
$(INCLUDE1)/xalloc.h \
$(INCLUDE1)/xerror.h
xerror.o: \ xerror.o: \
$(INCLUDE1)/xerror.c \ $(INCLUDE1)/xerror.c \
$(INCLUDE1)/xerror.h $(INCLUDE1)/xerror.h