LoginSignup
13
1

More than 1 year has passed since last update.

Livebook で kino_benchee (WIP)を動かしてみた

Posted at

はじめに

Kino の GitHub を見ていると、見慣れない単語が

Additionally, there are packages with components designed for a specific use cases. The officially supported ones are:

  • kino_vega_lite - for data charting
  • kino_db - for database integrations
  • kino_benchee - for rendering Benchee results

kino_benchee ?

すごく、そそる名前

Benchee は Elixir でベンチマークするためのモジュール

処理のパフォーマンス比較が簡単にできるのでいつも重宝しています

その Kino 版ということは、 Benchee の出力がますます魅力的になるはず!

なぜ今まで使っていなかったんだ?

と思ったら、まだ WIP でリリースされていませんでした

Benchee integration with Livebook.

Currently WIP.

しかし、どんなものか見ておきたい!

というわけで動かしてみました

以前並列処理を実装したノートブックを改造します

インストール

以下のようにして kino と kino_benchee を GitHub から最新版で取得します

Mix.install([
  {:download, "~> 0.0.4"},
  {:evision, "~> 0.1"},
  {:nx, "~> 0.4"},
  {:flow, "~> 1.2"},
  {:kino, github: "livebook-dev/kino", branch: :main, override: true},
  {:kino_benchee, "~> 0.1", github: "livebook-dev/kino_benchee", branch: "main"},
])

通常との比較

そのあとは以前の記事と同じように処理を実行します

すると、最後の Benchee を実行した結果がすごくキレイになります!

Benchee.run(%{
  "enum" => fn -> enum_proc.(stream) end,
  "flow 1" => fn -> flow_proc.(stream, 1) end,
  "flow 2" => fn -> flow_proc.(stream, 2) end,
  "flow 4" => fn -> flow_proc.(stream, 4) end,
  "flow 8" => fn -> flow_proc.(stream, 8) end
})

スクリーンショット 2022-12-07 17.43.20.png

パフォーマンス比較がデータテーブルとグラフになっています!

すごく視覚的!!

さらに memory_timereduction_time も見てみましょう

Benchee.run(
  %{
    "enum" => fn -> enum_proc.(stream) end,
    "flow 1" => fn -> flow_proc.(stream, 1) end,
    "flow 2" => fn -> flow_proc.(stream, 2) end,
    "flow 4" => fn -> flow_proc.(stream, 4) end,
    "flow 8" => fn -> flow_proc.(stream, 8) end
  },
  memory_time: 2,
  reduction_time: 2
)

benchee.gif

メモリ使用量の差が一目瞭然!

reduction については以下のリンクに説明があります

まとめ

kino_benchee の正式リリースが待ち遠しいですね

13
1
2

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