Junior — Middle
How can the duration of a specific process or task in the system be determined?
sobes.tech AI
Answer from AI
To determine the duration of a process or task in a system, you can measure the start and end times and then calculate the difference. Different programming languages and environments do this in various ways, but the general approach is as follows:
- Record the start time (for example, using a function to get the current time).
- Execute the process or task.
- Record the end time.
- Calculate the difference between the end time and the start time.
Example in Python:
import time
start_time = time.time()
# task code
time.sleep(2) # simulate work
end_time = time.time()
duration = end_time - start_time
print(f"Execution duration: {duration} seconds")
In systems with more advanced monitoring, you can use profilers or built-in logging tools for execution time.