diff --git a/CPP/Makefile b/CPP/Makefile index 80e256940064a20d3e7068e1a64464f62f0f94ca..94b8bdd6bf38f34b33073ef7d126f121b1c916f0 100644 --- a/CPP/Makefile +++ b/CPP/Makefile @@ -10,3 +10,7 @@ clean: rm -rf *.o rm -rf *~ rm -rf arraylist_analysis + + +%.o: %.cpp + $(CC) $(CPPFLAGS) -c $< -o $@ diff --git a/CPP/main.cpp b/CPP/main.cpp index acd896d8127a4d42b952bc0a147cc03c05b92b93..5109ead4d22ef5e83ca80b0452edd9b6a9787763 100644 --- a/CPP/main.cpp +++ b/CPP/main.cpp @@ -1,10 +1,13 @@ #include<iostream> -#include<time.h> +#include <chrono> #include<cstdlib> #include "arraylist.hpp" #include "analyzer.hpp" +using namespace std::chrono; + + int main(int argc, char ** argv){ int i; // Tableau dynamique. @@ -15,18 +18,19 @@ int main(int argc, char ** argv){ Analyzer copy_analysis; // Analyse de l'espace mémoire inutilisé. Analyzer memory_analysis; - struct timespec before, after; + high_resolution_clock::time_point before, after; // Booléen permettant de savoir si une allocation a été effectuée. bool memory_allocation; for(i = 0; i < 1000000 ; i++){ // Ajout d'un élément et mesure du temps pris par l'opération. - timespec_get(&before, TIME_UTC); + before = high_resolution_clock::now(); memory_allocation = a.append(i); - timespec_get(&after, TIME_UTC); + after = high_resolution_clock::now(); // Enregistrement du temps pris par l'opération - time_analysis.append(after.tv_nsec - before.tv_nsec); + auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(after - before); + time_analysis.append(static_cast<double>(duration.count())); // Enregistrement du nombre de copies efféctuées par l'opération. // S'il y a eu réallocation de mémoire, il a fallu recopier tout le tableau. copy_analysis.append( (memory_allocation)? i:1 ); @@ -47,3 +51,4 @@ int main(int argc, char ** argv){ return 0; } +