QuantumNoisemaker
Member
What's the best way to measure how long it takes for the Teensy 2.0++ to execute a portion of C code? There seem to be quite a few useful timer libraries available for C++, but I haven't been able to find as many methods in C. Here are the 4 possibilities I've seen so far:
Any tips as to which of the above four would be the best method to pursue, or if there is a better method that I am missing? Thanks for any input!
As an aside, one thing that I'm looking to test is whether my code handles the char type just as fast as the uint_fast8_t type as an input into a switch control flow. Theoretically they should be the same speed, but wanted to verify the implementation.
- PaulStoffregen mentions in this post (https://forum.pjrc.com/threads/61561-Teensy-4-Global-vs-local-variables-speed-of-execution?highlight=execution) that you can use the ARM_DWT_CYCCNT cycle counter on a 32-bit ARM processor to track clock cycles. Is there an equivalent for the 8-bit Atmel AT90USB1286?
- Most codes in C++ take advantage of the elapsedMillis/elapsedMicros and millis/micros libraries mentioned here (https://www.pjrc.com/teensy/td_timing.html). Is there a C library equivalent? (<Time.h> for AVR processors is missing the standard clock_t type that is usually used for this purpose (https://www.nongnu.org/avr-libc/user-manual/group__avr__time.html))
- The usb_serial example includes a tx_benchmark file which sets timer0 to overflow every 4 ms. The code:
Code:
// configure timer0 to overflow every 4 ms, prescale=256, top=250 // 250 * 256 / 16 MHz = 4 ms TIMSK0 = 0; TCCR0A = (1<<WGM01)|(1<<WGM00); OCR0A = 250; TCCR0B = (1<<WGM02)|(1<<CS02); ... // wait for a 4 ms timer0 period to begin CLEAR_TIMER0_OVERFLOW(); while (!IS_TIMER0_OVERFLOW()) /* wait */ ; CLEAR_TIMER0_OVERFLOW(); count=0;
- The most accurate method seems to be using an oscilloscope to measure an active pin on the board, but I don't have access to an oscilloscope and don't need that level of accuracy.
Any tips as to which of the above four would be the best method to pursue, or if there is a better method that I am missing? Thanks for any input!
As an aside, one thing that I'm looking to test is whether my code handles the char type just as fast as the uint_fast8_t type as an input into a switch control flow. Theoretically they should be the same speed, but wanted to verify the implementation.