0
0
Dockerdevops~5 mins

Running tests in containers in Docker - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Running tests in containers
O(n)
Understanding Time Complexity

When running tests inside Docker containers, it is important to understand how the time taken grows as the number of tests increases.

We want to know how the total test execution time changes when we add more tests to run in containers.

Scenario Under Consideration

Analyze the time complexity of the following Docker commands used to run multiple tests sequentially.


# Run tests one by one in separate containers
for test_script in test1.sh test2.sh test3.sh; do
  docker run --rm -v "$PWD":/app -w /app my-test-image sh "$test_script"
done
    

This script runs three test scripts one after another, each inside a new Docker container.

Identify Repeating Operations

Look for repeated actions that affect total time.

  • Primary operation: Starting a Docker container and running a test script inside it.
  • How many times: Once for each test script in the list.
How Execution Grows With Input

Each test runs in its own container, so total time adds up with more tests.

Input Size (n)Approx. Operations
3 tests3 container runs
10 tests10 container runs
100 tests100 container runs

Pattern observation: Total time grows directly with the number of tests because each test runs separately.

Final Time Complexity

Time Complexity: O(n)

This means the total time increases in a straight line as you add more tests to run in containers.

Common Mistake

[X] Wrong: "Running tests in containers happens all at once, so time stays the same no matter how many tests there are."

[OK] Correct: Each container starts and runs separately, so time adds up with each test unless you run them in parallel.

Interview Connect

Understanding how test execution time grows helps you design better test workflows and explain your choices clearly in real projects.

Self-Check

What if we ran all tests in parallel containers instead of one after another? How would the time complexity change?