UtilityToolsLab

© 2026 UtilityToolsLab. All rights reserved.

Privacy Policy·Terms of Service·Sitemap
HomeCompetitive ProgrammingStress Tester

Related Tools

Code FormatterMatrix GeneratorComplexity CalcBit VisualizerBitmask PlannerPrime FactorsMEX CalcInterval MergerMatrix RotationPBDS GeneratorSegment TreeGraph VisualizerModulo CalcBinary VisualizerConvex HullPath Finder

CP Stress Tester Generator

Paste your brute force, optimal solution, and test generator. Instantly get a downloadable Python or Bash stress test script that finds counter-examples automatically.

How to Use

  1. 1Open CP Stress Tester Generator above. No signup or installation needed.
  2. 2Type or paste your input. Everything runs locally in your browser — nothing leaves your device.
  3. 3See results instantly. Hit Copy to grab the output.
  4. 4Star the tool to save it to Favorites for quick access next time.

Frequently Asked Questions

Is Stress Tester free?

Yes, completely free. No sign-up, no credit card, no usage limits.

Do you store my data?

Never. Everything runs 100% in your browser. Nothing is uploaded to any server.

Does it work on mobile?

Yes. All tools are fully responsive and work on phones, tablets, and desktops.

Generated Stress Test Script (stress_test.py)

#!/usr/bin/env python3
"""
CP Stress Tester — generated by UtilityToolsLab
Finds the first counter-example between brute and optimal solutions.
"""
import subprocess, os, sys, tempfile

MAX_TESTS = 200

BRUTE_CODE = r"""
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    // brute force solution
    cout << n << endl;
}
"""

OPTIMAL_CODE = r"""
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    // optimal solution
    cout << n << endl;
}
"""

GEN_CODE = r"""
import random
import sys

# Generate random test case
n = random.randint(1, 100)
print(n)
"""

def write_file(path, content):
    with open(path, "w") as f:
        f.write(content)

def compile_cpp(src, out):
    result = subprocess.run(
        ["g++", "-O2", "-o", out, src],
        capture_output=True, text=True
    )
    if result.returncode != 0:
        print(f"Compile error:\n{result.stderr}")
        sys.exit(1)

def run_binary(binary, input_data):
    result = subprocess.run(
        [binary], input=input_data, capture_output=True, text=True, timeout=5
    )
    return result.stdout.strip()

def run_gen(gen_script):
    result = subprocess.run(
        [sys.executable, gen_script], capture_output=True, text=True, timeout=5
    )
    return result.stdout

def main():
    tmpdir = tempfile.mkdtemp()
    brute_src  = os.path.join(tmpdir, "brute.cpp")
    opt_src    = os.path.join(tmpdir, "optimal.cpp")
    gen_script = os.path.join(tmpdir, "gen.py")
    brute_bin  = os.path.join(tmpdir, "brute")
    opt_bin    = os.path.join(tmpdir, "optimal")

    print("Compiling brute force...")
    write_file(brute_src, BRUTE_CODE)
    compile_cpp(brute_src, brute_bin)

    print("Compiling optimal solution...")
    write_file(opt_src, OPTIMAL_CODE)
    compile_cpp(opt_src, opt_bin)

    write_file(gen_script, GEN_CODE)

    print(f"Running {MAX_TESTS} stress tests...\n")

    for t in range(1, MAX_TESTS + 1):
        test_input = run_gen(gen_script)
        out_brute  = run_binary(brute_bin,  test_input)
        out_opt    = run_binary(opt_bin,    test_input)

        if out_brute != out_opt:
            print(f"[COUNTER-EXAMPLE FOUND] Test #{t}")
            print(f"--- Input ---\n{test_input}")
            print(f"--- Brute Output ---\n{out_brute}")
            print(f"--- Optimal Output ---\n{out_opt}")
            with open("counter_example.txt", "w") as f:
                f.write(f"Input:\n{test_input}\nBrute:\n{out_brute}\nOptimal:\n{out_opt}")
            print("\nSaved to counter_example.txt")
            return

        if t % 50 == 0:
            print(f"  {t}/{MAX_TESTS} tests passed...")

    print(f"\n✅ All {MAX_TESTS} tests passed — no counter-example found!")

if __name__ == "__main__":
    main()

💡 Run with python3 stress_test.py or bash stress_test.sh — requires g++ and python3 installed locally.