Ai
1 Star 0 Fork 0

micropython中文社区/PiCalcTest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pi_circuitpython.py 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
shaoziyang 提交于 2022-03-15 21:44 +08:00 . add STM32/nrf/esp32/rt1062 result
import gc
from time import monotonic
import microcontroller
import os
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 = monotonic()
pi(n)
t2 = monotonic()
print(' ', (t2-t1)*1000, 'ms')
r = os.uname()
print('\n\n')
print('Pi calculation performance test')
print('===============================')
print('chip:', r.sysname)
print('ver: ', r.version)
print('Freq:', microcontroller.cpu.frequency)
print('Ram: ', gc.mem_free() + gc.mem_alloc())
for i in (100, 500, 1000, 2000, 5000, 10000, 100000):
try:
print('\nCalc {} bits pi'.format(i))
pi_t(i)
except:
print('Calc error!')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/micropython-chinese-community/PiCalcTest.git
git@gitee.com:micropython-chinese-community/PiCalcTest.git
micropython-chinese-community
PiCalcTest
PiCalcTest
main

搜索帮助