LoginSignup
13
1

More than 1 year has passed since last update.

Python vs Nerves(Elixir) Lチカ点滅速度競争

Last updated at Posted at 2022-09-04

Lチカの待ち時間を0にして最短点滅時間を調べてみました

実際に使うときに、こんなプログラムを書くことは無いですが、ベンチマークとしてやってみました。

比較条件

Target Raspberry Pi Zero W
Erlang 25.0.4 Elixir 1.13.4-otp-25
Python 3.4.2

Elixirのプログラム

  defp toggle_pin_forever(output_gpio) do
    GPIO.write(output_gpio, 1)
    GPIO.write(output_gpio, 0)
    toggle_pin_forever(output_gpio)
  end

Pythonのプログラム

while True:
    GPIO.output(pin_no, True)
    GPIO.output(pin_no, False)

結果

プログラム H時間 L時間 周期
Elixir(Nerves) 6.2μS 4.8μS 11.0μS
Python 5.0μS 5.4μS 10.4μS
C言語 0.080μS 0.084μS 0.164μS

僅差でPythonの勝ち

※ C言語(wiringPi使用)も追加しました。
圧倒的に速いですね

感想

ここまで僅差の勝負になるとは思いませんでした。もしかして、Elixirの方が圧倒的に速いのでは?と思ったんですが、そうでもなかったです。
PythonもByte Codeにコンパイルして実行してますからね。
いろいろな要素があるので、簡単に比較できませんが、極端な違いはないと解釈しました。

Elixirの結果
DS1Z_QuickPrint1.png

Pythonの結果
DS1Z_QuickPrint3.png

参考(C言語の結果)
DS1Z_QuickPrint4.png

13
1
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
13
1