Sobes.tech
Junior — Middle

Kuidas määrata konkreetse protsessi või ülesande kestus süsteemis?

sobes.tech AI

Vastus AI-lt

To determine the duration of a process or task execution in the system, you can measure the start and end times and then calculate the difference. In different programming languages and environments, this is done in various ways, but the general approach is as follows:

  • Record the start time (for example, using a function that gets 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, profilers or built-in logging tools can be used to record execution time.