This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Execution time on nrf52840

Hi,

What are the options to measure the execution time of code snippets? I used app_timer_cnt_get() now and is giving 50 ticks for 1ms. Is there any way I can measure lesser time?

Parents
  • The cycle counter works really well for short measurements:

    uint32_t start;
    uint32_t stop;
    uint32_t elapsed;
    
    // enable DWT
    CoreDebug->DEMCR |= 0x01000000;
    
    // Reset cycle counter
    DWT->CYCCNT = 0;
    
    // enable cycle counter
    DWT->CTRL |= 0x1;
    
    start = DWT->CYCCNT;
    nrf_delay_ms(1000);
    stop = DWT->CYCCNT;
    elapsed = stop-start;
    NRF_LOG_INFO("cycles for nrf_delay_ms(1000) = %u", elapsed);
    // <info> app: cycles for nrf_delay_ms(1000) = 64018002
    

Reply
  • The cycle counter works really well for short measurements:

    uint32_t start;
    uint32_t stop;
    uint32_t elapsed;
    
    // enable DWT
    CoreDebug->DEMCR |= 0x01000000;
    
    // Reset cycle counter
    DWT->CYCCNT = 0;
    
    // enable cycle counter
    DWT->CTRL |= 0x1;
    
    start = DWT->CYCCNT;
    nrf_delay_ms(1000);
    stop = DWT->CYCCNT;
    elapsed = stop-start;
    NRF_LOG_INFO("cycles for nrf_delay_ms(1000) = %u", elapsed);
    // <info> app: cycles for nrf_delay_ms(1000) = 64018002
    

Children
No Data
Related