# HG changeset patch # User Markus Bröker # Date 1239879039 -7200 # Node ID ded389a5dc2aca98d9d0ddb2e86d8523f79ae7fc # Parent b5912e5f899f810f9554a1eae712a895551cbc7e Profiling support added * To use the benefits of profiling, set PROFILING= * eg: mbroeker@localhost $ make -e PROFILING=linux * mbroeker@localhost $ export PROFILING=linux && make committer: Markus Bröker diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ - CC = gcc -g -ggdb - CPP = g++ -g -ggdb + CC = gcc -g -ggdb $(PROF) + CPP = g++ -g -ggdb $(PROF) CFLAGS = -Wall -O2 -Iinclude -ansi +ifeq ("$(PROFILING)", "linux") + PROF = -fprofile-arcs -ftest-coverage -pg +endif TARGET = ncurses TARGET += numerierung @@ -211,15 +214,15 @@ lotto: lotto.o @echo Linking $< ... - @$(CPP) -o $@ $< + @$(CC) -o $@ $< mem2swap: mem2swap.o set_limit.o @echo Linking $< ... - @$(CPP) -o $@ mem2swap.o set_limit.o + @$(CC) -o $@ mem2swap.o set_limit.o prog_limit: prog_limit.o set_limit.o @echo Linking $< ... - @$(CPP) -o $@ prog_limit.o set_limit.o + @$(CC) -o $@ prog_limit.o set_limit.o database: database.c @echo Compiling $< ... @@ -229,11 +232,11 @@ gauss: gauss.o @echo Linking $< ... - @$(CPP) -o $@ $< + @$(CC) -o $@ $< connection: connection.o @echo Linking $< ... - @$(CPP) -o $@ $< + @$(CC) -o $@ $< copy: copy.o @echo Linking $< ... @@ -300,6 +303,10 @@ clean: find -name '*~' -exec rm -f {} \; find -name '*.[oa]' -exec rm -f {} \; + find -name '*.gcov' -exec rm -f {} \; + find -name '*.gcda' -exec rm -f {} \; + find -name '*.gcno' -exec rm -f {} \; + find -name 'gmon.out' -exec rm -f {} \; rm -f $(TARGET) beauty: diff --git a/sort.c b/sort.c --- a/sort.c +++ b/sort.c @@ -40,7 +40,7 @@ } /** - * Laufzeitverhalten: n*(n-1) Durchläufe zum Sortieren von n Elementen... + * Laufzeitverhalten: n^2-1 Durchläufe zum Sortieren von n Elementen... */ void lazysort (int *v, int n, int (*compare_func) (int *, int *)) { @@ -57,13 +57,13 @@ } /** - * Laufzeitverhalten: (1/2)*n*(n-1) Durchläufe zum Sortieren von n Elementen... + * Laufzeitverhalten: (1/2)*n^2-1 Durchläufe zum Sortieren von n Elementen... */ void bubblesort (int *v, int n, int (*compare) (int *, int *)) { int i, j; - for (i = (n - 1); i >= 0; i--) { + for (i = (n - 1); i > 0; i--) { for (j = 1; j <= i; j++) { if (compare (&v[j - 1], &v[j])) { swap (v, j - 1, j);