sudo powermetrics will show info that tells you about your core clock frequency. The output may be very completely different between Intel and ARM processors.
It appears that evidently on Intel processors the precise clock frequency stays unchanged, however the CPUs might be unused some a part of the time. So you’ll be able to have output like
CPU Common frequency as fraction of nominal: 85.40% (1964.20 Mhz)
which suggests your CPU runs at 2,300 MHz, however solely 85.40% of the time. And that’s reported for every particular person CPU. I do not know what occurs in a “turbo” mode the place the clock velocity ought to supposedly be increased, or if the clock velocity goes down if the pc will get too sizzling.
An M1 or M2 processors has completely different output. On an M1 Professional, the eight efficiency cores can every run at 15 completely different speeds from 600 MHz to three,328 MHz; effectivity cores have 4 speeds from 600 MHz to 2,064 MHz. The device experiences for every core what proportion of time it spent at which clock velocity. And every processor could be idle; as a sort this, complete idle time is about 796% for the efficiency cores, so they’re solely used 4% of the time.
So on this case you have got eight cores, every able to operating at 3,328. Your choice is now what you name the clock velocity. You would name it 3,328 MHz till you get all cores operating and perhaps the clock velocity goes down a bit because of warmth.
Now programmatically: This device is sudo solely, so you’ll be able to’t simply launch it from an app. On an M1 Professional, you need to use clock_gettime_nsec_mp (CLOCK_THREAD_CPUTIME_ID) to get the time within the present thread with a decision of 42 nanoseconds on that exact processor (quicker and better decision than clock()). You then write a loop that runs for instance 1,000,000 iterations of a loop with 1 cycle per clock, measure the time, and calculate the clock velocity from that. clock_gettime_nsec_mp is kind of secure, so three measurements and throwing away the worst outlier ought to be tremendous. It might be a bit tough to put in writing a loop that does not get fully optimised away 🙂
If you’d like Intel clock speeds as properly, you might want a distinct loop, and examine what number of cycles it takes. And you could distinguish which processor is used, and keep away from utilizing Rosetta as a result of Rosetta runs ARM code however thinks it’s operating on Intel.