Page 1 of 1

CLOCKS_PER_SEC is 1000,000

Posted: Fri Sep 11, 2020 1:00 pm
by PeterR
v4.1, SHA-1: 84b51781c80740fda92784dafcfc96c13b0d8b66
ESP IDF legacy build under mingw32

Code: Select all

#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <mutex>

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

printf("TICKS: %d\n", CLOCKS_PER_SEC);
Yields 1000,000

However:

Code: Select all


#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <mutex>

printf("TICKS: %d\n", CLOCKS_PER_SEC);
Yields 1000

clock() returns ticks in milliseconds.

I could not find the definition of CLOCKS_PER_SEC in the IDF folder

Re: CLOCKS_PER_SEC is 1000,000

Posted: Sun Sep 13, 2020 7:53 am
by ESP_Sprite
It's likely defined in the libc headers in the toolchain, as it's a C thing. Not sure how useful it is in the first place; it feels kinda legacy-y with Posix just hard-defining it to a million.

Re: CLOCKS_PER_SEC is 1000,000

Posted: Mon Sep 14, 2020 2:28 pm
by PeterR
Thanks.

Seen the small print, doh!

EDIT: So is ESP-IDF POSIX?

Re: CLOCKS_PER_SEC is 1000,000

Posted: Tue Sep 15, 2020 9:37 am
by ESP_Sprite
Mostly, I think. POSIX is a large thing to be compatible with and has some details don't make sense for embedded systems (e.g. process management). We try to be pretty compatible to make it easy to port existing code over.