CLOCKS_PER_SEC is 1000,000

PeterR
Posts: 511
Joined: Mon Jun 04, 2018 2:47 pm

CLOCKS_PER_SEC is 1000,000

Postby PeterR » Fri Sep 11, 2020 1:00 pm

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
& I also believe that IDF CAN should be fixed.

ESP_Sprite
Posts: 3937
Joined: Thu Nov 26, 2015 4:08 am

Re: CLOCKS_PER_SEC is 1000,000

Postby ESP_Sprite » Sun Sep 13, 2020 7:53 am

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.

PeterR
Posts: 511
Joined: Mon Jun 04, 2018 2:47 pm

Re: CLOCKS_PER_SEC is 1000,000

Postby PeterR » Mon Sep 14, 2020 2:28 pm

Thanks.

Seen the small print, doh!

EDIT: So is ESP-IDF POSIX?
& I also believe that IDF CAN should be fixed.

ESP_Sprite
Posts: 3937
Joined: Thu Nov 26, 2015 4:08 am

Re: CLOCKS_PER_SEC is 1000,000

Postby ESP_Sprite » Tue Sep 15, 2020 9:37 am

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.

Who is online

Users browsing this forum: No registered users and 48 guests