LoginSignup
2
2

More than 5 years have passed since last update.

めざせpythonライブラリマスター (10)timeit

Last updated at Posted at 2016-06-03

【ライブラリ説明】

 コードの実行時間を計測します

【プログラム】

timeit1.py
# -*- coding: utf-8 -*-

def test():
    L = []
    for i in range(100):
        L.append(i)

if __name__ == '__main__':
    import timeit
    print(timeit.timeit("test()", setup="from __main__ import test"))
    # 10.1292455843
timeit2.py
# -*- coding: utf-8 -*-

def test():
    L = []
    for i in range(10):
        L.append(i)

if __name__ == '__main__':
    import timeit
    print(timeit.timeit("test()", setup="from __main__ import test"))
    # 1.57425508033

【参考サイト】

 timeit

2
2
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
2
2