0
0
Agentic AIml~10 mins

Latency and cost benchmarking in Agentic AI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to measure the latency of a function call.

Agentic AI
import time
start = time.[1]()
result = my_function()
end = time.perf_counter()
latency = end - start
print(f"Latency: {latency} seconds")
Drag options to blanks, or click blank then click option'
Aperf_counter
Bsleep
Ctime
Dprocess_time
Attempts:
3 left
💡 Hint
Common Mistakes
Using time.sleep() instead of a timer function.
Using time.time() which has lower resolution.
2fill in blank
medium

Complete the code to calculate the average cost per API call given total cost and number of calls.

Agentic AI
total_cost = 50.0  # dollars
num_calls = 200
average_cost = total_cost [1] num_calls
print(f"Average cost per call: ${average_cost:.4f}")
Drag options to blanks, or click blank then click option'
A/
B*
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Multiplying total cost by number of calls.
Adding or subtracting instead of dividing.
3fill in blank
hard

Fix the error in the code to correctly record the latency of multiple runs and compute the average latency.

Agentic AI
import time
latencies = []
for _ in range(5):
    start = time.perf_counter()
    run_task()
    end = time.[1]()
    latencies.append(end - start)
avg_latency = sum(latencies) / len(latencies)
print(f"Average latency: {avg_latency:.5f} seconds")
Drag options to blanks, or click blank then click option'
Asleep
Btime
Cprocess_time
Dperf_counter
Attempts:
3 left
💡 Hint
Common Mistakes
Using time.time() for end but perf_counter() for start.
Using sleep instead of a timer.
4fill in blank
hard

Fill both blanks to create a dictionary of API call latencies filtered by calls longer than 0.1 seconds.

Agentic AI
latency_data = {call_id: [1] for call_id, [2] in api_calls.items() if latency > 0.1}
Drag options to blanks, or click blank then click option'
Alatency
Bduration
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable name for both blanks.
Using undefined variable names.
5fill in blank
hard

Fill all three blanks to create a filtered dictionary of call costs where cost is above 0.05 dollars and keys are uppercase.

Agentic AI
filtered_costs = [1]([2]: cost for [3], cost in call_costs.items() if cost > 0.05)
Drag options to blanks, or click blank then click option'
Adict
Bk.upper()
Ck
Dv
Attempts:
3 left
💡 Hint
Common Mistakes
Not converting keys to uppercase.
Using wrong variable names in comprehension.