All problems
Latency For Target Throughput
Problem
Given ascending batch sizes and their measured latencies in milliseconds, find the smallest batch whose throughput batch_size / latency_ms * 1000 reaches target_tps, and return its latency. Return -1.0 if no batch reaches the target.
The signature is latency_for_target_throughput(batch_sizes, latencies, target_tps).
Hint
Batch sizes are ascending, so the first batch that meets the target is also the lowest-latency one.
Test cases
case 1
in: [[1,2,4,8],[10,12,30,50],150]
expected: 12
case 2
in: [[1,2,4,8],[10,12,30,50],1500]
expected: -1
case 3
in: [[1,4,16],[5,10,40],300]
expected: 10
case 4
in: [[2],[20],100]
expected: 20
Starter codePython
def latency_for_target_throughput(batch_sizes, latencies, target_tps):
# Your code here
pass4 test cases · run your code against them in the editor