A Visual Studio Code extension for programmers to fetch LeetCode problems, set up local C++ testing environments, and stress-test your solutions with random and sample test cases—all from within your editor.
demovid.mp4

-
Problem Fetching: Instantly fetch LeetCode problems by ID or title, including samples, code snippets, and official solutions.
-
Automated Setup: Creates a dedicated
stress tester/directory with C++ files (solution.cpp,brute.cpp,gen.cpp) and input/output handlers. -
Sample Testing: Run your solution against LeetCode sample cases with parallel execution for speed.
-
Stress Testing: Generate random test cases via
gen.cpp, compare your solution against a brute-force implementation, and detect discrepancies. -
Visual Interface: Interactive panel with real-time progress, logs, pass/fail indicators, and detailed failure reports.
-
Customization: Easily modify
gen.cppfor tailored random inputs; configure test count and timeouts via VS Code settings. -
Cross-Platform: Works seamlessly on Windows and Linux with automatic compiler detection (g++).
-
Debugging Aids: Saves all inputs/outputs for failed tests; uses precompiled headers for faster builds.
Below is a architecture diagram of the LeetCode Stress Tester extension. It shows how the components interact to fetch problems, compile code, and run tests.
- Open VS Code.
- C++ compiler
- Node.js and npm for packaging
- Clone the Repository:
git clone https://github.com/ShubhamNegi4/Leetcode-Stress-Tester.git
cd leetcode-stress-tester
- Install Dependencies:
npm install
- Package the Extension:
- Install
vsceglobally:
npm install -g vsce
- Package:
vsce package
- This generates a
.vsixfile.
-
Install in VS Code:
-
Open VS Code.
-
Go to Extensions view (
Ctrl+Shift+X). -
Click the
...menu and selectInstall from VSIX.... -
Choose the
.vsixfile.
-
-
Verify: Reload VS Code and look for the "Stress Tester" icon in the activity bar.
- Click the beaker icon in the VS Code activity bar to open the "Stress Tester" panel.
-
Enter a LeetCode problem ID (e.g., "1") or slug (e.g., "two-sum") in the input field.
-
Click Fetch Problem.
-
Downloads problem data via LeetCode GraphQL API.
-
Sets up
stress tester/directory with files. -
Extracts samples into
textIO/input.txt(editable format: input --- output). -
Fetches official or GitHub brute-force solution into
brute.cpp. -
Generates
solution.cppwith LeetCode C++ snippet inserted into a canonical template.
-
-
Open
stress tester/solution.cpp. -
Write your code inside the provided class/method.
-
The template handles input/output automatically.
-
** Run Samples:** Tests against samples in
textIO/input.txt. Runs in parallel (up to 4-16 workers based on CPU). -
** Run Stress Tests:** Generates random cases via
gen.cpp, runssolution.cppandbrute.cpp, compares outputs. -
Configurable: Set
leetcodeStressTester.testCount(default: 100) andtimeLimitMs(default: 2000ms) in VS Code settings.
Results appear in the panel with logs, progress bars, and failure details.
The extension handles compilation automatically when running tests. Here's a detailed breakdown:
-
Created in
stress tester/pch/if not present. -
Content:
#include <bits/stdc++.h> -
Command:
${compiler} -std=c++17 "stdc++.h" -o "stdc++.h.gch" -
Used via
-include stdc++.hflag for faster compiles. -
Generated only once; delete
stdc++.h.gchto regenerate.
Note: If error encountered, please update your gcc (recommended: 13.x.x)
-
solution.cpp:
-std=c++17 -O2 -pipe -march=native -DNDEBUG -include <pch> -
brute.cpp:
-std=c++17 -O1 -pipe -DNDEBUG -include <pch>(simpler optimization for brute force) -
gen.cpp:
-std=c++17 -O2 -pipe -DNDEBUG -include <pch>
-
Detect compiler.
-
Generate/check precompiled header.
-
Compile each file if needed (always recompiles for safety).
-
Use
spawnSyncto run compilation commands. -
On Windows, appends
.exeto executables.
Compilation happens before tests and takes ~1-2 seconds with precompiled headers.
gen.cpp generates random test cases for stress testing. It's crucial for finding edge cases.
-
Generates random inputs (e.g., arrays, numbers) based on problem constraints.
-
Uses
<random>for randomness. -
Outputs in JSON-per-line format (e.g.,
[1,2,3]\n5).
-
Understand Inputs: Refer to the problem for required format (e.g., array + target).
-
Add Constraints: Use random_device for seeds; generate within limits (e.g., 1 <= n <= 1e5).
-
Example Modification:
// In main():
mt19937 rng(random_device{}());
int n = uniform_int_distribution<int>(1, 1000)(rng);
cout << n << endl;
for(int i = 0; i < n; i++) cout << uniform_int_distribution<int>(-100, 100)(rng) << ' ';
cout << endl;
-
Minute Details: Ensure outputs match the expected input format for
solution.cppandbrute.cpp. Usejson.hppif needed for complex structures. -
Best Practices: Start small, increase complexity; test gen.cpp independently by compiling and running it.
After fetching a problem:
Leetcode-Stress-Tester/
├── stress tester/
│ ├── solution.cpp # Your solution code
│ ├── brute.cpp # Brute-force/official solution
│ ├── gen.cpp # Random test generator
│ ├── pch/ # Precompiled headers
│ │ ├── stdc++.h
│ │ └── stdc++.h.gch
│ ├── textIO/
│ │ ├── input.txt # Editable samples (input --- output)
│ │ ├── all_input.txt # Stress inputs
│ │ ├── solution_output.txt
│ │ └── brute_output.txt
│ └── utils/
│ ├── json.hpp # JSON parser
│ └── template.cpp # Canonical template
└── ... (other project files)
Customize via VS Code settings (Ctrl+,):
-
leetcodeStressTester.testCount: Number of stress tests (default: 100). -
leetcodeStressTester.timeLimitMs: Per-test timeout (default: 2000ms).
-
Compiler Not Found: Please upgrade gcc ( recommended 13.x.x or more )
-
Compilation Errors: Check logs in the panel; fix syntax in .cpp files.
-
No Samples: Edit
textIO/input.txtmanually. -
Spaces in Paths: Handled automatically in latest version.
-
Slow Builds: Precompiled headers should help; delete
pch/to regenerate.
For issues, check the VS Code output panel ("LeetCode Stress Tester").
Contributions welcome! Fork the repo, make changes, and submit a PR.
-
Report bugs in Issues.
-
Suggest features or improvements.

