Μεταγλώττιση και εκτέλεση του κώδικα
Πρόγραμμα οδηγός (main)
- linked_list.hpp header συνδεδεμένης λίστας
- linked_list.cpp υλοποίηση συνδεδεμένης λίστας
-
main.cpp πρόγραμμα οδηγός
$ g++ linked_list.cpp main.cpp -o main -std=c++11 $./main CHECK 1 [push_front] 23 90 11 78 16 22 70 CHECK 2 [length + sum] LENGTH 7 SUM 310 CHECK 3 [erase_front] 90 11 78 16 22 70 CHECK 4 [push_back] 90 11 78 16 22 70 10 CHECK 5 [bubble_sort] 10 11 16 22 70 78 90 CHECK 6 [copy constructor] 10 11 16 22 70 78 90 CHECK 7 [delete_at_position 3] 10 11 16 70 78 90 CHECK 8 [insert_at_position 3 value 54] 10 11 16 54 70 78 90 CHECK 9 [reverse] 90 78 70 54 16 11 10
Πρόγραμμα ελέγχου (tests)
- linked_list.hpp header συνδεδεμένης λίστας
- linked_list.cpp υλοποίηση συνδεδεμένης λίστας
- tests_main.cpp αρχείο για μείωση χρόνου μεταγλώττισης λόγω της CATCH https://github.com/catchorg/Catch2/blob/master/docs/slow-compiles.md
- tests.cpp αρχείο που περιέχει τα unit tests
-
Εντολές μεταγλώττισης
$ g++ linked_list.cpp -c -std=c++11 $ g++ tests_main.cpp -c -std=c++11 $ g++ linked_list.o tests_main.o tests.cpp -o tests -std=c++11 $ ./tests =============================================================================== All tests passed (39 assertions in 7 test cases)
Σύγκριση ταχυτήτων μεταγλώττισης για τους ελέγχους με το catch (8.16sec –> 0.82sec)
-
Με μεταγλώττιση όλων των αρχείων
$ time g++ linked_list.cpp tests_main.cpp tests.cpp -o tests -std=c++11 g++ linked_list.cpp tests_main.cpp tests.cpp -o tests -std=c++11 8.16s user 0.38s system 99% cpu 8.609 total
-
Με ξεχωριστή μεταγλώττιση (έχει προηγηθεί η μεταγλώττιση των linked_list.cpp και tests_main.cpp)
% time g++ linked_list.o tests_main.o tests.cpp -o tests -std=c++11 g++ linked_list.o tests_main.o tests.cpp -o tests -std=c++11 0.82s user 0.08s system 99% cpu 0.905 total
Makefile
-
$ make main g++ linked_list.cpp -c -std=c++11 g++ main.cpp -c -std=c++11 g++ linked_list.o main.o -o main -std=c++11 $ make main make: `main' is up to date. $ ./main CHECK 1 [push_front] 23 90 11 78 16 22 70 CHECK 2 [length + sum] LENGTH 7 SUM 310 CHECK 3 [erase_front] 90 11 78 16 22 70 CHECK 4 [push_back] 90 11 78 16 22 70 10 CHECK 5 [bubble_sort] 10 11 16 22 70 78 90 CHECK 6 [copy constructor] 10 11 16 22 70 78 90 CHECK 7 [delete_at_position 3] 10 11 16 70 78 90 CHECK 8 [insert_at_position 3 value 54] 10 11 16 54 70 78 90 CHECK 9 [reverse] 90 78 70 54 16 11 10 $ make tests g++ tests_main.cpp -c -std=c++11 g++ linked_list.o tests_main.o tests.cpp -o tests -std=c++11 $ ./tests -r compact Passed all 7 test cases with 39 assertions.
-
$ make -f makefile2.mk main ... $ make -f makefile2.mk tests ...