Glib is a fantastic lib
This commit is contained in:
parent
325f7a739c
commit
accb7dcc8f
|
@ -18,3 +18,10 @@ cscope
|
||||||
.ctags
|
.ctags
|
||||||
.cscope
|
.cscope
|
||||||
|
|
||||||
|
syntax: regexp
|
||||||
|
#[^.]+[.][^.]+$
|
||||||
|
#[!]re:[^.]+[.][^.]+$
|
||||||
|
#^(?!(scripts|foo|bar)/)[^/]+/
|
||||||
|
#^[^.]*$
|
||||||
|
#^(\.c$)
|
||||||
|
#[.]+/[^\.]+$
|
||||||
|
|
|
@ -4,23 +4,26 @@
|
||||||
# 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>
|
||||||
|
|
||||||
#_________________________________
|
#_________________________________
|
||||||
# ENVIRONMENT |
|
# ENVIRONMENT |
|
||||||
#________________________________|
|
#________________________________|
|
||||||
CC=cc
|
|
||||||
CXX=c++
|
|
||||||
LIBRARIES=-lstdc++
|
|
||||||
TARGET0=realloc_speed_test_c
|
TARGET0=realloc_speed_test_c
|
||||||
TARGET1=realloc_speed_test_cpp
|
TARGET1=realloc_speed_test_cpp
|
||||||
TARGET= $(TARGET0) $(TARGET1)
|
TARGET2=realloc_speed_test_glib
|
||||||
INCLUDE1=$(HOME)/projects/include
|
TARGETS= $(TARGET0) $(TARGET1) $(TARGET2)
|
||||||
INCLUDE2=/usr/local/include
|
CC=cc
|
||||||
INCLUDE=-I$(INCLUDE1) -I$(INCLUDE2)
|
CXX=c++
|
||||||
|
LIBS=-lglib-2.0 -lstdc++
|
||||||
|
SRC1=$(HOME)/projects/texreport/mod-alloc
|
||||||
|
SRC2=$(HOME)/projects/texreport/mod-err
|
||||||
|
SRC=-I$(SRC1) -I$(SRC2)
|
||||||
|
INCLUDES=-I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
|
||||||
#________________________________________
|
#________________________________________
|
||||||
# BUILD SCRIPT (don't change) |
|
# BUILD SCRIPT (don't change) |
|
||||||
#_______________________________________|
|
#_______________________________________|
|
||||||
|
@ -28,26 +31,26 @@ 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 $(INCLUDES)
|
||||||
LDFLAGS += -Wall $(LIBRARIES)
|
LDFLAGS += -Wall $(LIBS)
|
||||||
|
|
||||||
all: change_make_options $(TARGET)
|
all: change_make_options $(TARGETS)
|
||||||
|
|
||||||
ifneq ($(mode),debug)
|
ifneq ($(mode),debug)
|
||||||
ifneq ($(mode),profile)
|
ifneq ($(mode),profile)
|
||||||
|
@ -73,16 +76,16 @@ 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 :
|
||||||
$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
|
$(CC) -c $(CFLAGS) $(SRC) -o $@ $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) *.o *.out callgrind.out.* *.gcno $(TARGET)
|
$(RM) *.o *.out callgrind.out.* *.gcno $(TARGETS)
|
||||||
|
|
||||||
.PHONY: all change_make_options clean
|
.PHONY: all change_make_options clean
|
||||||
|
|
||||||
|
@ -105,19 +108,32 @@ $(TARGET1): $(target_objs1)
|
||||||
$(CC) $(LDFLAGS) -o $@ $(target_objs1)
|
$(CC) $(LDFLAGS) -o $@ $(target_objs1)
|
||||||
|
|
||||||
|
|
||||||
|
target_objs2 = \
|
||||||
|
realloc_speed_test_glib.o \
|
||||||
|
xalloc.o \
|
||||||
|
xerror.o
|
||||||
|
|
||||||
|
$(TARGET2): $(target_objs2)
|
||||||
|
$(CC) $(LDFLAGS) -o $@ $(target_objs2)
|
||||||
|
|
||||||
|
|
||||||
realloc_speed_test_c.o: \
|
realloc_speed_test_c.o: \
|
||||||
realloc_speed_test_c.c \
|
realloc_speed_test_c.c \
|
||||||
$(INCLUDE1)/xalloc.h
|
$(SRC1)/xalloc.h
|
||||||
|
|
||||||
realloc_speed_test_cpp.o: \
|
realloc_speed_test_cpp.o: \
|
||||||
realloc_speed_test_cpp.cpp
|
realloc_speed_test_cpp.cpp
|
||||||
|
|
||||||
|
realloc_speed_test_glib.o: \
|
||||||
|
realloc_speed_test_glib.c \
|
||||||
|
$(SRC1)/xalloc.h
|
||||||
|
|
||||||
xalloc.o: \
|
xalloc.o: \
|
||||||
$(INCLUDE1)/xalloc.c \
|
$(SRC1)/xalloc.c \
|
||||||
$(INCLUDE1)/xalloc.h \
|
$(SRC1)/xalloc.h \
|
||||||
$(INCLUDE1)/xerror.h
|
$(SRC2)/xerror.h
|
||||||
|
|
||||||
xerror.o: \
|
xerror.o: \
|
||||||
$(INCLUDE1)/xerror.c \
|
$(SRC2)/xerror.c \
|
||||||
$(INCLUDE1)/xerror.h
|
$(SRC2)/xerror.h
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
fputs("Usage: realloc_speed_test_cpp iterations nobj\n", stderr);
|
fputs("Usage: realloc_speed_test_c iterations nobj\n", stderr);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include "xalloc.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (argc != 3) {
|
||||||
|
fputs("Usage: realloc_speed_test_glib iterations nobj\n", stderr);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t iterations = (size_t)atoi(argv[1]);
|
||||||
|
size_t nobj = (size_t)atoi(argv[2]);
|
||||||
|
|
||||||
|
GString **p = malloc(sizeof(GString *) * nobj);
|
||||||
|
memset(p, 0, sizeof(void *) * nobj);
|
||||||
|
|
||||||
|
size_t i, idx, sz;
|
||||||
|
for (i = 0; i < nobj; i++)
|
||||||
|
p[i] = g_string_new(0);
|
||||||
|
|
||||||
|
for (i = 0; i < iterations; i++) {
|
||||||
|
idx = (size_t)(rand() % (int)nobj);
|
||||||
|
sz = i;
|
||||||
|
p[idx] = g_string_append_c(p[idx], 'c');//realloc(p[idx], sz);
|
||||||
|
|
||||||
|
if (sz && !p[idx]) {
|
||||||
|
fprintf(stderr, "Alloc error at i = %lu\n", i);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < nobj; i++)
|
||||||
|
g_string_free(p[i], FALSE);
|
||||||
|
|
||||||
|
free(p);
|
||||||
|
|
||||||
|
printf("Success, iterations = %lu, nobj = %lu\n", iterations, nobj);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Loading…
Reference in New Issue