Skip to main content

Overview

The stress command verifies that your solution executes within the specified time and memory limits across multiple randomly generated test cases. Unlike cmp, it doesn’t verify correctness against another solution—it only checks performance.
Use stress when you’re confident your solution is correct but want to ensure it runs fast enough for contest constraints.

Basic Usage

quicktest stress --target-file=main.cpp --gen-file=gen.cpp
Or using the shorter alias:
qt stress -t main.cpp -g gen.cpp

Required Parameters

target-file
string
required
Your solution file to stress test. Can be any supported language (C++, Java, Python, Rust, Go, C, Kotlin).Short form: -t
--target-file=main.cpp
-t main.cpp
gen-file
string
required
Random test case generator file that produces input data.Short form: -gDefault: "" (empty - can use --prefix instead)
The generator and prefix options are mutually exclusive. Use either --gen-file for random generation or --prefix to run existing test cases.
--gen-file=gen.cpp
-g gen.cpp

Optional Parameters

test-cases
number
default:"1000"
Number of test cases to generate and run.Alias: --tc
--test-cases=500
--tc 500
timeout
number
default:"2000"
Maximum execution time per test case in milliseconds.Alias: --tout
--timeout=1000
--tout 1000
memory-limit
number
default:"1000000000"
Memory limit in bytes (default is 1GB).Alias: --ml
--memory-limit=512000000
--ml 512000000
prefix
string
default:""
Path prefix for existing test case files. Use this to stress test against pre-existing test cases.Short form: -pConflicts with: --gen-file
--prefix=test_cases/testcase_ac
-p test_cases/testcase_ac

Control Flags

break-bad
boolean
default:"false"
Stop execution immediately when a TLE (Time Limit Exceeded) or RTE (Runtime Error) occurs.Aliases: --break, -b
--break-bad
--break
-b

Save Options

The --save-all and --save-bad flags are mutually exclusive.
save-bad
boolean
default:"false"
Save only test cases that fail (TLE, RTE, MLE states).
--save-bad
save-all
boolean
default:"false"
Save all test cases regardless of their result.
--save-all

Run Filters

Use these flags to run specific subsets of previously saved test cases:
run-all
boolean
default:"false"
Run all saved test cases.
run-ac
boolean
default:"false"
Run only test cases that previously passed (Accepted status).
run-wa
boolean
default:"false"
Run only test cases that previously failed with Wrong Answer.
run-tle
boolean
default:"false"
Run only test cases that previously exceeded time limit.
run-mle
boolean
default:"false"
Run only test cases that previously exceeded memory limit.
run-rte
boolean
default:"false"
Run only test cases that previously had runtime errors.

Examples

Basic Stress Test

qt stress -t main.cpp -g gen.cpp --tc 15 --tout 1000

Detect TLE Cases

1

Run stress test with save-bad

Find test cases that exceed time limits:
qt stress -t main.cpp -g gen.cpp --tc 100 --tout 1000 --save-bad
2

Analyze TLE cases

Re-run only the TLE cases to investigate:
qt stress -t main.cpp -g gen.cpp --run-tle
3

Verify optimization

After optimizing, test against the previously failing cases:
qt stress -t main.cpp -g gen.cpp --run-tle --break-bad

Strict Time Constraints

Test with strict competitive programming time limits (1 second):
qt stress -t main.cpp -g gen.cpp --tc 1000 --tout 1000 --break-bad

Memory-Intensive Problems

Set a custom memory limit (256MB):
qt stress -t main.cpp -g gen.cpp --tc 500 --ml 268435456

Using Existing Test Cases

Run stress tests against pre-generated test files:
qt stress -t main.cpp -p test_cases/testcase_ac --tc 10
When using --prefix, QuickTest looks for files named like testcase_ac_01.txt, testcase_ac_02.txt, etc.

Complete Example with Generator

Here’s a complete stress testing scenario:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> values(n);
    for(int &a: values)
        cin >> a;
    
    // O(n) solution
    int best = 0, sum = 0;
    for (int i = 0; i < n; i++) {
        sum = max(values[i], sum + values[i]);
        best = max(best, sum);
    }
    cout << best << "\n";
    return 0;
}
Run the stress test:
qt stress -t main.cpp -g gen.cpp --tc 50 --tout 1000 --save-bad

Comprehensive Testing Session

Save all test cases for later analysis:
qt stress -t main.cpp -g gen.cpp --tc 1000 --tout 2000 --save-all
Then run specific subsets:
# Check all previously accepted cases still pass
qt stress -t main.cpp -g gen.cpp --run-ac

# Re-test any TLE cases
qt stress -t main.cpp -g gen.cpp --run-tle

# Run everything again
qt stress -t main.cpp -g gen.cpp --run-all

Understanding Test Results

QuickTest displays real-time results with status indicators:
  • AC - Accepted (passed within time/memory limits)
  • TLE - Time Limit Exceeded
  • MLE - Memory Limit Exceeded
  • RTE - Runtime Error
Since stress doesn’t compare outputs, you won’t see WA (Wrong Answer) status. Use the cmp command if you need correctness verification.

When to Use Stress

Performance Testing

Verify your solution meets time constraints for large inputs

Optimization Validation

Confirm optimizations actually improve runtime

Memory Profiling

Test memory-intensive solutions against limits

Regression Testing

Ensure code changes don’t introduce performance issues

Tips

Generate realistic test sizes: Configure your generator to create test cases close to the problem’s maximum constraints.
Use —break-bad for quick feedback: During optimization, stop at the first TLE to save time.
Compare before and after: Save all test cases before optimizing, then run the same cases after to measure improvement.
Don’t ignore AC with close times: If your solution passes but uses 90%+ of the time limit, it may TLE on different test data or slower systems.

See Also

  • cmp - Compare against a correct solution
  • check - Use custom checker for validation
  • output - Generate output files from test cases

Build docs developers (and LLMs) love