How to measure processing time in Python or Java

If the processing performance requirements are severe, you may be concerned about the processing time of the implemented processing. This time I would like to leave a memorandum on how to measure the processing time in Python and Java.

How to measure processing time with Python

Measure processing time


# -*- coding: utf-8 -*-
import time

# main
if __name__ == "__main__":

    #Start time
    startTime = time.time()
    
    #Processing of measurement target
    # processing

    #End time
    endTime = time.time()
    
    #Display of processing time
    print(endTime - startTime)

How to measure processing time in Java

Measure processing time


public class TimeWatchDemo {
    
    public static void main(String[] args) {

        //Start time
        long startTime = System.nanoTime();
        
        //Processing of measurement target
        // processing
        
        //Completion time
        long endTime = System.nanoTime();
        
        //Display of processing time
        System.out.println(endTime - startTime);
    }
}

Recommended Posts

How to measure processing time in Python or Java
A clever way to time processing in Python
How to measure execution time with Python Part 1
How to measure execution time with Python Part 2
How to develop in Python
How to measure mp3 file playback time with python
[Python] How to do PCA in Python
How to collect images in Python
How to use SQLite in Python
Measure function execution time in Python
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
How to use PubChem in Python
How to handle Japanese in Python
How to generate exponential pulse time series data in python
Sample code to get started with GLSL shaders in Processing (either Java or Python)
How to access environment variables in Python
How to dynamically define variables in Python
How to do R chartr () in Python
How to make a string into an array or an array into a string in Python
Express Python yield in JavaScript or Java
[Itertools.permutations] How to put permutations in Python
How to work with BigQuery in Python
How to write offline real time Solve E04 problems in Python
How to get a stacktrace in python
How to display multiplication table in python
How to extract polygon area in Python
How to check opencv version in python
How to switch python versions in cloud9
How to adjust image contrast in Python
How to use __slots__ in Python class
How to dynamically zero pad in Python
How to use regular expressions in Python
How to display Hello world in python
How to use is and == in Python
How to write Ruby to_s in Python
How to calculate "xx time" in one shot with Python timedelta
How to display bytes in the same way in Java and Python
How to get the date and time difference in seconds with python
How to format a list of dictionaries (or instances) well in Python
Python: I want to measure the processing time of a function neatly
[Python] How to open two or more files at the same time
How to stop a program in python until a specific date and time
How to use the C library in Python
How to receive command line arguments in Python
3 ways to parse time strings in python [Note]
How to clear tuples in a list (Python)
How to do multi-core parallel processing with python
How to embed a variable in a python string
Strategy on how to monetize with Python Java
How to implement Discord Slash Command in Python
How to achieve time wait processing with wxpython
Summary of how to import files in Python 3
Type Python scripts to run in QGIS Processing
How to simplify restricted polynomial fit in python
How to use Python Image Library in python3 series
How to implement shared memory in Python (mmap.mmap)
How to create a JSON file in Python
Summary of how to use MNIST in Python
How to specify TLS version in python requests