0

I can't print clock_t as a double or print time elapsed

void app_main()
{
 clock_t start, end;
 long double cpu_time_used;
 start = clock();
 
 ESP_LOGI(TAG, "Elapsed time");
 ESP_LOGI(TAG, "Starting time: %Lf", (long double)start);
 end = clock();
 ESP_LOGI(TAG, "Ending time: %ld", end);
 cpu_time_used = (( long double) (end - start)) / CLOCKS_PER_SEC;
 ESP_LOGI(TAG, "Elapsed time: %Lf ms", cpu_time_used);
}

and this is my log:

I (241) application using mex: Elapsed time

I (243) application using mex: Starting time:

I (248) application using mex: Ending time: 2

I (255) application using mex: Elapsed time: ms

I (264) application using mex: Elapsed time: s

I really don't understand why

0

1 Answer 1

0

Try printing a double. I suspect your ESP_LOGI() does not support long double.

IAC double is sufficient precision and range.

Use ESP_LOGI(TAG, "Starting time: %f", (double)start); or for exact value try ESP_LOGI(TAG, "Starting time: %a", (double)start);.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.