-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Benchmark: measure the run time of the script on the html x times, then do the average. #1889
Comments
Over the years I had only one request of such a feature (yours), so I don't feel like our users are the target-group for such a feature. I'll leave this in as a Feature Suggestion for now. |
Maybe because they are not newbies. I just started and like to experiment what code is faster etc.. This feature would be a very comfortable assistance from jsfiddle part, with a nice little button |
// Function to run your code
function yourCode() {
// Replace this with whatever code you want to run repeatedly
// For example, a simple math operation like addition
let sum = 0;
for(let i = 0; i < 1000; i++) {
sum += i;
}
return sum;
}
function runTest() {
const duration = 60000; // Run for 60 seconds
const startTime = performance.now(); // Get start time
let currentTime = startTime;
let totalRuns = 0;
let totalRunTime = 0;
let minRunTime = Infinity; // Initialize minimum runtime
// Loop until the elapsed time exceeds 10 seconds
while (currentTime - startTime < duration) {
const runStartTime = performance.now(); // Start time for this run
yourCode(); // Call the function repeatedly
const runEndTime = performance.now(); // End time for this run
const runTime = runEndTime - runStartTime; // Calculate the run time
totalRunTime += runTime; // Accumulate total run time
totalRuns++; // Increment the number of runs
// Update minimum run time
if (runTime < minRunTime) {
minRunTime = runTime;
}
currentTime = performance.now(); // Update the current time
}
// Calculate the average time per run
const averageTime = totalRunTime / totalRuns;
console.log(`Total runs: ${totalRuns}`);
console.log(`Total time spent: ${totalRunTime.toFixed(2)} ms`);
console.log(`Average time per run: ${averageTime.toFixed(2)} ms`);
console.log(`Minimum run time: ${minRunTime.toFixed(2)} ms`);
}
// Start the test
runTest(); This is an example of how the feature can be reproduced on the user part. It's just annoying to set up. JUST a nice and comfortable button to trigger the test, so good. |
PS: Give people a taste of the benchmark feature, they will love it (even because nobody else has it) |
Description
I would like a way to measure the run code x times on the html and then get the average time, for easy test purposes.
Would this feature be feasible?
To cope I currently use
performance.now()
to measure the run time of the code like here: https://jsfiddle.net/udq02rjL/(I made the html very long with lots of strings)
I would like the website to do that for easy comfort testing.
Other Details
Regex101 just added the benchmark feature where it applies the regex continuously for 10 seconds.
You can try it here: https://regex101.com/r/eIqVlC/1
The text was updated successfully, but these errors were encountered: