0
0
Rest APIprogramming~5 mins

Load testing in Rest API - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Load testing
O(n)
Understanding Time Complexity

Load testing checks how a system handles many requests at once.

We want to know how the system's work grows as more users send requests.

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


// Simulate handling multiple API requests
function handleRequests(requests) {
  requests.forEach(request => {
    processRequest(request);
  });
}

function processRequest(request) {
  // Process each request (fixed time)
}
    

This code processes each incoming request one by one.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Loop over all requests.
  • How many times: Once for each request received.
How Execution Grows With Input

As the number of requests grows, the work grows in the same way.

Input Size (n)Approx. Operations
1010 processRequest calls
100100 processRequest calls
10001000 processRequest calls

Pattern observation: Doubling requests doubles the work.

Final Time Complexity

Time Complexity: O(n)

This means the time to handle requests grows directly with the number of requests.

Common Mistake

[X] Wrong: "Handling more requests takes the same time as handling one."

[OK] Correct: Each request needs its own processing, so more requests mean more total work.

Interview Connect

Understanding how work grows with users helps you design systems that stay fast under pressure.

Self-Check

"What if processRequest took longer for some requests? How would that affect the time complexity?"