Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6078

General • Re: Pico 2 RISC-V - Slow....

$
0
0
When I have been doing simplistic comparisons I have usually simply added one to a variable until it hits a million or used Fibonacci calculation, usually 'Fibo(24) == 46368' as my de facto standard, as it's a demanding enough task but doesn't take too long.

Not truly benchmarks but good enough to be used for comparisons in my experience. Best thing they are easy enough to code from memory.

Code:

set(PROJECT fibonacci)cmake_minimum_required(VERSION 3.12)include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)project(${PROJECT} C CXX ASM)pico_sdk_init()add_executable(${PROJECT} main.c)target_compile_options(${PROJECT} PRIVATE -Wall -Werror)target_link_libraries(${PROJECT} pico_stdlib)pico_add_extra_outputs(${PROJECT})pico_enable_stdio_usb(${PROJECT} 1)pico_enable_stdio_uart(${PROJECT} 0)pico_set_binary_type(${PROJECT} no_flash)

Code:

#include <stdio.h>#include "pico/stdlib.h"uint32_t Fibo(uint32_t n){  if ( n <= 1 ) { return n; }  else          { return Fibo(n-1) + Fibo(n-2); }}void Benchmark(char* name, uint32_t (*func)(uint32_t), uint32_t arg) {  uint64_t tStart = time_us_64();  uint32_t result = (*func)(arg);  uint64_t tEnd   = time_us_64();  printf("%s(%ld) = %ld in %lld us\n", name, arg, result, tEnd - tStart);}int main(){  stdio_init_all();  while(1)  {    Benchmark("Fibo",  Fibo,  24);      // Fibo(24) = 46368    sleep_ms(1000);  }}

Code:

Fibo(24) = 46368 in 22543 us # RP2040 B.0 / PicoFibo(24) = 46368 in 22543 us # RP2040 B.2 / Pico W

Statistics: Posted by hippy — Sat Aug 17, 2024 3:20 pm



Viewing all articles
Browse latest Browse all 6078

Trending Articles