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 5 years have passed since last update.

PythonやJavaで処理時間を計測する方法

Posted at

処理性能の要件がシビアな場合、実装した処理の処理時間が気になることがあると思います。今回はPythonとJavaにおける処理時間を計測する方法について備忘録として記事に残したいと思います。

Pythonで処理時間を計測する方法

処理時間を計測
# -*- coding: utf-8 -*-
import time

# main
if __name__ == "__main__":

    # 開始時刻
    startTime = time.time()
    
    # 計測対象の処理
    # processing

    # 終了時刻
    endTime = time.time()
    
    # 処理時間の表示
    print(endTime - startTime)

Javaで処理時間を計測する方法

処理時間を計測
public class TimeWatchDemo {
    
    public static void main(String[] args) {

        // 開始時刻
        long startTime = System.nanoTime();
        
        // 計測対象の処理
        // processing
        
        // 修了時刻
        long endTime = System.nanoTime();
        
        // 処理時間の表示
        System.out.println(endTime - startTime);
    }
}
0
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
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?