Skip to content

Instantly share code, notes, and snippets.

@devlights
Created May 7, 2018 08:50
Show Gist options
  • Save devlights/1b65ad15f28d26b500112b140143be41 to your computer and use it in GitHub Desktop.
Save devlights/1b65ad15f28d26b500112b140143be41 to your computer and use it in GitHub Desktop.
[python][ipython] timeit マジックコマンドについてのメモ

ipython の timeit マジックコマンド

%timeit

In [1]: %timeit 1+1
28.3 ns ± 4.08 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

単一のステートメントの実行時間を測定する。

%%timeit

In [2]: %%timeit
   ...: a = 1+1
   ...: b = 2+2
   ...: a+b
   ...:
96.3 ns ± 4.22 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

複数行の実行時間を測定する。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment