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;
try {
v[idx].resize(sz);
} catch(...) {
fprintf(stderr, "Alloc error at i = %lu\n", i);
exit(-1);

View File

@ -10,6 +10,7 @@
#include <string.h>
#include "zalloc.h"
#include "zalloc_ext.h"
int main(int argc, char *argv[])
{
@ -28,7 +29,7 @@ int main(int argc, char *argv[])
for (i = 0; i < iterations; i++) {
idx = (size_t)(rand() % (int)nobj);
sz = i;
zrealloc_inplace(&p[idx], sz);
p[idx] = zrealloc(p[idx], sz);//zrealloc_inplace(&p[idx], sz);
if (sz && !p[idx]) {
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,
# because the Makefile containes rules for automatically clean.
# Some usage examples:
# CFLAGS="-march=core2 -mtune=core2" make
# LDFLAGS="-lexpat" make mode=profile
# make # default mode is debug
# 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>
#_________________________________
@ -13,9 +15,11 @@
#________________________________|
CC=cc
CXX=c++
LIBRARIES=
TARGET0=zalloc_ext_test
TARGET= $(TARGET0)
LIBRARIES=-lstdc++
TARGET0=std_string_speed_test
TARGET1=zalloc_speed_test_c
TARGET2=zalloc_ext_test
TARGET= $(TARGET0) $(TARGET1) $(TARGET2)
INCLUDE1=$(HOME)/projects/include
INCLUDE2=/usr/local/include
INCLUDE=-I$(INCLUDE1) -I$(INCLUDE2)
@ -27,20 +31,20 @@ ifeq ($(mode),)
mode = debug
endif
ifeq ($(mode),debug)
CFLAGS = -O0 -g -std=gnu99 -pedantic -Wextra -Wconversion
LDFLAGS =
CFLAGS := -O0 -g -std=gnu99 -pedantic -Wextra -Wconversion $(CFLAGS)
LDFLAGS := $(LDFLAGS)
endif
ifeq ($(mode),profile)
CFLAGS = -O0 -g -p -ftest-coverage -Wcoverage-mismatch
LDFLAGS = -g -p
CFLAGS := -O0 -g -p -ftest-coverage -Wcoverage-mismatch $(CFLAGS)
LDFLAGS := -g -p $(LDFLAGS)
endif
ifeq ($(mode),develop)
CFLAGS += -O2 -g
LDFLAGS += -O1
CFLAGS := -O2 -g $(CFLAGS)
LDFLAGS := -O1 $(LDFLAGS)
endif
ifeq ($(mode),release)
CFLAGS += -O2
LDFLAGS += -O1
CFLAGS := -O2 $(CFLAGS)
LDFLAGS := -O1 $(LDFLAGS)
endif
CFLAGS += -Wall
@ -72,9 +76,9 @@ change_make_options:
ifneq ($(mode)|$(CFLAGS)|$(LDFLAGS), $(OLD_BUILD_MODE)|$(OLD_BUILD_CFLAGS)|$(OLD_BUILD_LDFLAGS))
@echo CLEANING...
@make clean &>/dev/null
@echo MODE=$(mode) > make_options.out
@echo CFLAGS=$(CFLAGS) >> make_options.out
@echo LDFLAGS=$(LDFLAGS) >> make_options.out
@echo "MODE=$(mode)" > make_options.out
@echo "CFLAGS=$(CFLAGS)" >> make_options.out
@echo "LDFLAGS=$(LDFLAGS)" >> make_options.out
endif
%.o :
@ -89,27 +93,47 @@ clean:
# R U L E S |
#________________________________|
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 \
xalloc.o \
xerror.o \
zalloc.o \
zalloc_ext.o
$(TARGET0): $(target_objs0)
$(CC) $(LDFLAGS) -o $@ $(target_objs0)
$(TARGET2): $(target_objs2)
$(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.c \
$(INCLUDE1)/xalloc.h \
$(INCLUDE1)/zalloc.h \
$(INCLUDE1)/zalloc_ext.h
xalloc.o: \
$(INCLUDE1)/xalloc.c \
$(INCLUDE1)/xalloc.h \
$(INCLUDE1)/xerror.h
zalloc.o: \
$(INCLUDE1)/zalloc.c \
$(INCLUDE1)/xerror.h \
@ -120,6 +144,11 @@ zalloc_ext.o: \
$(INCLUDE1)/zalloc.h \
$(INCLUDE1)/zalloc_ext.h
xalloc.o: \
$(INCLUDE1)/xalloc.c \
$(INCLUDE1)/xalloc.h \
$(INCLUDE1)/xerror.h
xerror.o: \
$(INCLUDE1)/xerror.c \
$(INCLUDE1)/xerror.h