Skip to content
Snippets Groups Projects
Commit 5010fdaf authored by david's avatar david
Browse files

modified measure of time CPP

parent b7799206
No related branches found
No related tags found
No related merge requests found
...@@ -10,3 +10,7 @@ clean: ...@@ -10,3 +10,7 @@ clean:
rm -rf *.o rm -rf *.o
rm -rf *~ rm -rf *~
rm -rf arraylist_analysis rm -rf arraylist_analysis
%.o: %.cpp
$(CC) $(CPPFLAGS) -c $< -o $@
#include<iostream> #include<iostream>
#include<time.h> #include <chrono>
#include<cstdlib> #include<cstdlib>
#include "arraylist.hpp" #include "arraylist.hpp"
#include "analyzer.hpp" #include "analyzer.hpp"
using namespace std::chrono;
int main(int argc, char ** argv){ int main(int argc, char ** argv){
int i; int i;
// Tableau dynamique. // Tableau dynamique.
...@@ -15,18 +18,19 @@ int main(int argc, char ** argv){ ...@@ -15,18 +18,19 @@ int main(int argc, char ** argv){
Analyzer copy_analysis; Analyzer copy_analysis;
// Analyse de l'espace mémoire inutilisé. // Analyse de l'espace mémoire inutilisé.
Analyzer memory_analysis; 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éen permettant de savoir si une allocation a été effectuée.
bool memory_allocation; bool memory_allocation;
for(i = 0; i < 1000000 ; i++){ for(i = 0; i < 1000000 ; i++){
// Ajout d'un élément et mesure du temps pris par l'opération. // 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); memory_allocation = a.append(i);
timespec_get(&after, TIME_UTC); after = high_resolution_clock::now();
// Enregistrement du temps pris par l'opération // 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. // 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. // S'il y a eu réallocation de mémoire, il a fallu recopier tout le tableau.
copy_analysis.append( (memory_allocation)? i:1 ); copy_analysis.append( (memory_allocation)? i:1 );
...@@ -47,3 +51,4 @@ int main(int argc, char ** argv){ ...@@ -47,3 +51,4 @@ int main(int argc, char ** argv){
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment