Skip to main content

Practice · 2 of 2

N+1 query counter

CHALLENGE
Difficulty: advanced+25 XP

Given orders (List<string> ids) each needing one query for its lines: a naive loop issues 1 + N queries. Implement static int NaiveQueries(int orderCount) = orderCount + 1, and static int BatchedQueries(int orderCount, int batchSize) = ceil(orderCount / batchSize) + 1 (batch IN-queries). Then implement static (int naive, int batched, double saved) Compare(int orderCount, int batchSize) returning all three with saved = round((naive − batched) / naive × 100, 2).

Back to lesson: Practice: Data access drills