Bird
0
0

Identify the error in this latency measurement code:

medium📝 Troubleshoot Q6 of 15
Agentic AI - Agent Observability
Identify the error in this latency measurement code:
import time
latencies = {}
start = time.time()
time.sleep(0.1)
latencies['step1'] = start - time.time()
print(latencies['step1'])
AUsing sleep with float value causes error
BMissing import statement for time module
CSubtracting current time from start time gives negative latency
DDictionary key 'step1' is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check latency calculation

    Latency should be end_time - start_time, not start_time - end_time.
  2. Step 2: Result of wrong subtraction

    Subtracting current time from start time yields negative value.
  3. Final Answer:

    Subtracting current time from start time gives negative latency -> Option C
  4. Quick Check:

    Latency calculation order matters [OK]
Quick Trick: Always subtract start time from end time [OK]
Common Mistakes:
  • Reversing subtraction order
  • Assuming negative latency is valid
  • Ignoring correct time import

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes