0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

検証シリーズ: micro:bit 「ずっと」ブロックと「ループ」ブロックのスピード比較

Posted at

便利なので使いがちな「ずっと」ブロック、そして比べると少し考えて作らないといけない「ループ」ブロックの比較をしてみました。

前回のこちらの続編です

「ずっと」ブロックのカウントの方法

プログラム開始から3秒間で1ループごと(ずっとのループ)にカウントしていき、何回カウントしたかを記録します。

サンプルプログラム
https://makecode.microbit.org/S51245-11164-75403-66263

microbit-画面コピー (12).png

「ループ」ブロックのカウントの方法

Aボタンを押してからの3秒間で1ループごとにカウントしていき、何回カウントアップしたかを記録します。

サンプルプログラム
https://makecode.microbit.org/S60449-87521-71357-70859

microbit-画面コピー (11).png

比較結果

3秒間でのカウントアップ比較ですが、結果は「ループ」ブロックの圧勝です。
ほとんどの処理はどちらを使っても同じですが、センサーで厳密な処理をしたい場合などは「ループ」ブロックを使った方がよいですね。

ブロック種別 シミュレーター 実機
「ずっと」ブロック 146回 151回
「ループ」ブロック 約2,000万回 約50万回
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?