I am trying to calculate the average execution time of a program, for 10 executions, for this I use the library chrono
of C ++ 11, however, I'm getting an error that says there is no operator to make +=
, I understand that variables declared as auto
can be matched with other types of data.
Code:
int i=0;
float execution_time=0;
while(i<10){
auto start = chrono::system_clock::now();
coche_.A_star(map_);//para llamar a A_star,asi se implementan constructores
auto end = chrono::system_clock::now();
auto elapsed = chrono::duration_cast<std::chrono::seconds>(end - start);
execution_time += elapsed; //ERROR
i++;
}
cout << "tiempo de ejecucion" << execution_time/10 <<endl;
Error:
error: no match for ‘operator+=’ (operand types are ‘float’ and ‘std::chrono::duration<long int>’)
execution_time += elapsed;
The code is part of a larger function, I only put what is relevant to understand the doubt. I have declared using namespace std
.
Thanks, thanks.