import gc
from utime import ticks_ms, ticks_diff
import machine
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 = ticks_ms()
pi(n)
t2 = ticks_ms()
print(' ', ticks_diff(t2, t1), 'ms')
r = os.uname()
print('\n\n')
print('Pi calculation performance test')
print('===============================')
print('chip:', r.sysname)
print('ver: ', r.version)
try:
print('Freq:', machine.freq())
except:
print('Freq: unknow')
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!')
-
近期文章
近期评论
- admin 发表在《PDF文件分割图片》
- admin 发表在《混乱的五月即将告以段路》
- admin 发表在《系规看来不是300页那么简单》
- admin 发表在《系规看来不是300页那么简单》
- admin 发表在《扩展计划UserScript》
归档
- 2026 年 2 月
- 2026 年 1 月
- 2025 年 12 月
- 2025 年 11 月
- 2025 年 10 月
- 2025 年 9 月
- 2025 年 8 月
- 2025 年 7 月
- 2025 年 6 月
- 2025 年 5 月
- 2025 年 4 月
- 2025 年 3 月
- 2025 年 2 月
- 2025 年 1 月
- 2024 年 12 月
- 2024 年 11 月
- 2024 年 10 月
- 2024 年 9 月
- 2024 年 8 月
- 2024 年 7 月
- 2024 年 6 月
- 2024 年 5 月
- 2024 年 4 月
- 2024 年 2 月
- 2024 年 1 月
- 2023 年 12 月
- 2023 年 11 月
- 2023 年 10 月
- 2022 年 10 月
- 2022 年 9 月
- 2022 年 8 月
- 2022 年 7 月
- 2022 年 6 月
- 2022 年 5 月
- 2022 年 4 月
- 2022 年 3 月
- 2022 年 1 月
- 2021 年 11 月
- 2021 年 10 月
- 2021 年 9 月
- 2021 年 4 月
- 2020 年 11 月
- 2020 年 10 月
- 2020 年 8 月
- 2020 年 5 月
- 2020 年 4 月
- 2020 年 1 月
- 2019 年 11 月
- 2019 年 7 月
- 2019 年 2 月
- 2019 年 1 月
- 2018 年 12 月
- 2018 年 11 月
- 2018 年 8 月
分类
友情链接
其他操作