ESP32-S2-Saola-1 算圆周率
<div class='showpostmsg'><p>习惯上,我用算圆周率来比较MCU的性能。因为python支持大整数运算,圆周率计算正好用到大整数,可以初步体现出MCU的整数计算性能。</p><p> </p>
<p>下面程序是在以前microython的圆周率计算程序上稍作修改,将时间函数ticks_ms()改为monotonic()。程序需要先保存到文件,然后import 执行(circuitpython 不支持 execfile函数)。如果直接粘贴,大概率假死,这应该是系统的bug。</p>
<p> </p>
<pre>
<code class="language-python">from time import monotonic
def calc_pi(places=100):
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 = 500):
t1 = monotonic()
calc_pi(n)
t2 = monotonic()
return t2 - t1
print('calc pi 100 bits:', pi_t(100), 's')
print('calc pi 1000 bits:', pi_t(1000), 's')
print('calc pi 5000 bits:', pi_t(5000), 's')
</code></pre>
<p> </p>
<p>运行效果</p>
<p> </p>
<p></p>
<p> </p>
<p> </p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>和其它MCU的比较:<a href="https://github.com/shaoziyang/micropython_benchmarks/tree/master/1.9.4-479">https://github.com/shaoziyang/micropython_benchmarks/tree/master/1.9.4-479</a></p>
<p> </p>
<p>在ESP32-S2上,1000位比ESP32快,5000位慢,感觉没有发挥ESP32-S2性能,内存部分还可以提高优化效率。等circuitpython正式版出来再正式比较。</p>
页:
[1]