Profiling support added
authorMarkus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:50:39 +0200
changeset 70 ded389a5dc2a
parent 69 b5912e5f899f
child 71 9ac5a589211e
Profiling support added * To use the benefits of profiling, set PROFILING=<target> * eg: mbroeker@localhost $ make -e PROFILING=linux * mbroeker@localhost $ export PROFILING=linux && make committer: Markus Bröker <mbroeker@largo.homelinux.org>
Makefile
sort.c
--- 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:
--- 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);