def get_elapsed_time():
        """
			Is the option for one of the following methods to measure
				time?
				* perf_counter, perf_counter(): pc_timestamp()
				* process_time, process_time(): pt_timestamp()
				* time, time.time_ns(): time_ns()
				* monotonic, monotonic(): pm_monotonic()
		"""
        if ("perf_counter" == execution_time_measurement_no_ns.
                get_type_current_time_measurement()):
            # Yes. Use perf_counter() to measure performance/time.
            current_timestamp = pc_timestamp()
        elif ("process_time" == execution_time_measurement_no_ns.
              get_type_current_time_measurement()):
            # Yes. Use process_time() to measure performance/time.
            current_timestamp = pt_timestamp()
        elif ("time" == execution_time_measurement_no_ns.
              get_type_current_time_measurement()):
            # Yes. Use time.time() to measure performance/time.
            current_timestamp = time.time()
        else:
            """
				The default option is: "monotonic".
				Use monotonic() to measure performance/time.
			"""
            current_timestamp = pm_monotonic()
        # Postcondition. Check if elapsed_time_no_ns > 0.
        elapsed_time_no_ns = current_timestamp - execution_time_measurement_no_ns.get_initial_timestamp(
        )
        execution_time_measurement_no_ns.check_elapsed_time(elapsed_time_no_ns)
        return elapsed_time_no_ns
예제 #2
0
    def get_elapsed_time(type_timestamp="monotonic_ns"):
        """
			Is the option for one of the following methods to measure
				time?
				* perf_counter, perf_counter(): pc_timestamp()
				* perf_counter_ns, perf_counter_ns(): pc_timestamp_ns()
				* process_time, process_time(): pt_timestamp()
				* process_time_ns, process_time_ns(): pt_timestamp_ns()
				* time, time.time(): time()
				* time_ns, time.time_ns(): time_ns()
				* monotonic, monotonic(): pm_monotonic()
				* monotonic_ns, monotonic_ns(): pm_monotonic_ns()
		"""
        if ("perf_counter" == type_timestamp):
            # Yes. Use perf_counter() to measure performance/time.
            current_timestamp = pc_timestamp()
        elif ("perf_counter_ns" == type_timestamp):
            # Yes. Use perf_counter_ns() to measure performance/time.
            current_timestamp = pc_timestamp_ns()
        elif ("process_time" == type_timestamp):
            # Yes. Use process_time() to measure performance/time.
            current_timestamp = pt_timestamp()
        elif ("process_time_ns" == type_timestamp):
            # Yes. Use process_time_ns() to measure performance/time.
            current_timestamp = pt_timestamp_ns()
        elif ("time" == type_timestamp):
            # Yes. Use time.time() to measure performance/time.
            current_timestamp = time.time()
        elif ("time_ns" == type_timestamp):
            # Yes. Use time.time_ns() to measure performance/time.
            current_timestamp = t_ns()
        elif ("monotonic" == type_timestamp):
            # Yes. Use monotonic() to measure performance/time.
            current_timestamp = pm_monotonic()
        else:
            """
				The default option is: "monotonic_ns".
				Use monotonic_ns() to measure performance/time.
			"""
            current_timestamp = pm_monotonic_ns()
        return (current_timestamp -
                execution_time_measurement.get_initial_timestamp())
    def set_initial_timestamp(type_timestamp="monotonic"):
        execution_time_measurement_no_ns.type_current_time_measurement = type_timestamp
        """
			Is the option for one of the following methods to measure
				time?
				* perf_counter, perf_counter(): pc_timestamp()
				* process_time, process_time(): pt_timestamp()
				* time, time.time(): time.time()
				* monotonic, monotonic(): pm_monotonic()
		"""
        if ("perf_counter" == type_timestamp):
            # Yes. Use perf_counter() to measure performance/time.
            execution_time_measurement_no_ns.initial_timestamp = pc_timestamp()
        elif ("process_time" == type_timestamp):
            # Yes. Use process_time() to measure performance/time.
            execution_time_measurement_no_ns.initial_timestamp = pt_timestamp()
        elif ("time" == type_timestamp):
            # Yes. Use time() to measure performance/time.
            execution_time_measurement_no_ns.initial_timestamp = time.time()
        else:
            # The default option is: "monotonic()"
            execution_time_measurement_no_ns.initial_timestamp = pm_monotonic()
)

# Time units in seconds (s).
initial_timestamp = time.time()
# Time units in nanoseconds (ns).
current_timestamp = t_ns()
elapsed_time = current_timestamp - initial_timestamp
print("initial_timestamp via time.time() is:", initial_timestamp, ".")
print("current_timestamp via time.time_ns() is:", current_timestamp, ".")
print("elapsed_time is:", elapsed_time, ".")
print(
    "	Error! Combining time measurements in seconds and nanosecond precision would store their values in different time units."
)

# Time units in seconds (s).
initial_timestamp = pm_monotonic()
# Time units in nanoseconds (ns).
current_timestamp = pm_monotonic_ns()
elapsed_time = current_timestamp - initial_timestamp
print("initial_timestamp via monotonic is:", initial_timestamp, ".")
print("current_timestamp via monotonic_ns is:", current_timestamp, ".")
print("elapsed_time is:", elapsed_time, ".")
print(
    "	Error! Combining time measurements in seconds and nanosecond precision would store their values in different time units."
)

print("")
print(
    "Conclusion: Cannot combine time measurements in seconds and in nanoseconds."
)
print("")