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?

mruby/cをmrubyで測定

Last updated at Posted at 2024-08-13

いつ出るかわからないメッセージを目視してベンチマークをストップウォッチで測るのはたいへんなので、mrubyで測定してみました。

mrubyはMac miniのElCapitanで動かしました。ElCapitanではmruby3はビルドできなかったのでmruby2です。mruby-serialportを入れてビルドしました。

mrubyのスクリプトはこれです。

sp = SerialPort.new("/dev/cu.usbserial-A1032R9E", 38400, 8, 1, 0)

count = 0
last = 0
while 1
  sp.getc
  if count != 0 then
    t = Time.now.to_i - last
    print count.to_s + ":" + t.to_s + "\n"
  end
  last = Time.now.to_i
  count += 1
end

シリアルから1バイト受け取るごとに経過時間を表示します。

mrubycのsupport_tools/benchmarks/merge_sort.rbを以下のようにして実機で動かします。

serial_init()

while true
  serial_write('@'.ord)
  1000.times do
    merge_sort(ary)
  end
end

merge_sortの結果

CPU 1回目 2回目 3回目
RX210 440 440 440
RX631 207 207 206

hanoiの結果

CPU 1回目 2回目 3回目
RX210 x x x
RX631 60 59 60

RX210では動作しませんでした。メモリが足りないのかもしれません。

fib(32)

CPU 1回目 2回目 3回目
RX210 192 191 191
RX631 90 89 90

fib(32) - ビルド時にNDEBUGを設定してassertを無効化

CPU 1回目 2回目 3回目
RX210 137 137 137
RX631 64 65 65
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?