0
0
Gitdevops~5 mins

Automated testing on push in Git - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Automated testing on push
O(n)
Understanding Time Complexity

When code is pushed to a repository, automated tests run to check for errors. We want to understand how the time taken to run these tests changes as the number of tests grows.

How does adding more tests affect the total time before feedback?

Scenario Under Consideration

Analyze the time complexity of this git hook running automated tests on push.


#!/bin/sh
# pre-push hook

echo "Running automated tests..."
for test in tests/*.sh; do
  sh "$test" || exit 1
 done
 echo "All tests passed!"

This script runs each test script in the tests folder one by one before allowing the push.

Identify Repeating Operations
  • Primary operation: Running each test script once.
  • How many times: Once per test script in the tests directory.
How Execution Grows With Input

As the number of test scripts increases, the total time grows proportionally because each test runs separately.

Input Size (n)Approx. Operations
10Runs 10 tests
100Runs 100 tests
1000Runs 1000 tests

Pattern observation: Doubling the number of tests roughly doubles the total time.

Final Time Complexity

Time Complexity: O(n)

This means the total time grows linearly with the number of tests run on each push.

Common Mistake

[X] Wrong: "Running more tests won't affect push time much because they run fast."

[OK] Correct: Even fast tests add up when many run one after another, so total time grows with test count.

Interview Connect

Understanding how test count affects push time helps you design better workflows and explain trade-offs clearly in real projects.

Self-Check

"What if tests ran in parallel instead of one by one? How would the time complexity change?"