2295 views|3 replies

1w

Posts

25

Resources
The OP
 

【RPi PICO】 Pi calculation test [Copy link]

 

Like other MCUs, we can test the performance of RP2040 by calculating pi.

import gc
from utime import ticks_ms, ticks_diff
 
def pi(places=100):
  # 3 + 3*(1/24) + 3*(1/24)*(9/80) + 3*(1/24)*(9/80)*(25/168)
  # The numerators 1, 9, 25, ... are given by (2x + 1) ^ 2
  # The denominators 24, 80, 168 are given by (16x^2 -24x + 8)
  extra = 8
  one = 10 ** (places+extra)
  t, c, n, na, d, da = 3*one, 3*one, 1, 0, 0, 24
 
  while t > 1: 
    n, na, d, da = n+na, na+8, d+da, da+32
    t = t * n // d
    c += t
  return c // (10 ** extra)
 
def pi_t(n=1000):
    gc.collect()
    t1 = ticks_ms()
    pi(n)
    t2 = ticks_ms()
    print('  ', ticks_diff(t2, t1), 'ms')
 
for i in (100, 500, 1000, 5000, 10000):
    try:
        print('\nCalc {} bits pi'.format(i))
        pi_t(i)
    except:
        print('Calc error!')

Operation Results

Calc 100 bits pi
17 ms

Calc 500 bits pi
190 ms

Calc 1000 bits pi
665 ms

Calc 5000 bits pi
19950 ms

Calc 10000 bits pi
74292 ms

It can be seen that the computing performance of RP2040 with M0+ core is close to that of STM32F411, lower than that of STM32F405, but much stronger than nRF51822 with the same M0+ core.

Latest reply

Can this run similar scores to dhystone?   Details Published on 2021-2-1 15:52
 
 

2940

Posts

0

Resources
2
 

Not bad, thumbs up.

 
 
 

7172

Posts

195

Resources
3
 

Can this run similar scores to dhystone?

Comments

Programming in C should be possible.  Details Published on 2021-2-1 17:27
 
 
 

1w

Posts

25

Resources
4
 
Changjianze1 posted on 2021-2-1 15:52 Can this run similar scores to dhystone?

It should be possible to program in C. The performance improvement brought by the high main frequency is obvious.

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list