0
2

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

Posted at

2**x と 1<<xの速度比較をしてみました。
下の表は秒です。

$ python3 -m timeit '2**__'
$ python3 -m timeit '1<<__'
50000000 loops, best of 5: ___ nsec per loop

↑ここは変わります
※ u(μ)secはnsecに変換します。

x 2**x 1<<x
20 6.61 6.7
50 6.48 6.56
100 428 6.4
200 590 66.8
500 1170 66.4
1000 1740 70.3
2000 3190 73
5000 9620 193
10000 21700 190

以上。シフト演算子<<の方が断然早いでしょう。

0
2
1

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?