I have written one program to calculate the execution time of the function. I want to display the execution time of it. I am using chrono library and using the high_precision_clock function of it. But still I am getting runtime as 0.
void primsCall(){
Prims prm(vec, adjMatrix);
auto start = high_resolution_clock::now();
prm.formMST(vec, adjMatrix);
auto stop = high_resolution_clock::now();
auto duration = duration_cast<nanoseconds>(stop-start);
cout<<"Prim's Algorithm MST: (total cost: "<<prm.mstCost<<"; runtime: "<<duration.count()<< "ms)"<<endl;
for(string entry : prm.path){
cout<<entry<<endl;
}
return;
}
Also I have used different function of chrono:
void kruskalSCall(){
cout<<endl<<endl;
Kruskal ksk(vec, adjMatrix);
clock_t start, end;
start = clock();
ksk.formMST(vec);
end = clock();
double runtime = double(end - start);
cout<<"Kruskal's Algorithm MST: (total cost: "<<ksk.kMstCost<<"; runtime: "<<runtime<< "ms)"<<endl;
for(string entry : ksk.kPath){
cout<<entry<<endl;
}
return;
}
But in both the cases my output is 0.
Prim's Algorithm MST: (total cost: 15; runtime: 0ms) (1,3) (3,6) (6,4) (3,2) (2,5)
Kruskal's Algorithm MST: (total cost: 15; runtime: 0ms) (1,3) (4,6) (2,5) (3,6) (2,3)
Please suggest me to calculate the time of execution.
Aucun commentaire:
Enregistrer un commentaire