Magicode logo
Magicode
1 min read

python のファイル全体の実行時間の計測方法

https://cdn.apollon.ai/media/notebox/blob_AgQVjuQ
python
import pytz
from datetime import datetime

def main():
    print("Hello world!")

if __name__ == "__main__":

    start = datetime.now(pytz.timezone('Asia/Tokyo'))
    print()
    main()
    print()


    print("Train Started at {}".format(start))
    finish = datetime.now(pytz.timezone('Asia/Tokyo'))
    print("Train Finished at {}".format(finish))
    print("Elapsed Time: {}".format(finish - start))

Hello world! Train Started at 2022-07-01 13:23:46.152907+09:00 Train Finished at 2022-07-01 13:23:46.156002+09:00 Elapsed Time: 0:00:00.003095

Discussion

コメントにはログインが必要です。