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

More than 1 year has passed since last update.

[Python] %%timeitの回数設定

1
Posted at

Jupyter Notebook(IPython)では、timeitモジュールをインポートせずに、マジックコマンド%%timeitが使える。

%%timeitでは、セル全体の実行時間を計測する。

  • r:繰り返し回数
  • n:ループ回数
%%timeit -r 3 -n 10000
import numpy as np
a = np.arange(n)
np.sum(a)

# 19.7 µs ± 9.57 µs per loop (mean ± std. dev. of 3 runs, 10000 loops each)

処理時間の長いコードで行う際などに、実行回数は以下のように指定できる。

%%timeit -r 1 -n 1

#
# 処理
#
1
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
1
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?