Open Palloxin opened 1 month ago
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.. Maybe someone experienced could do a loop and do the exact same I asked.
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. This issue is basically about a QoL feature. I didnt see a similar thing on JSFiddle alike websites. It would be a good addition to make it more unique.
JUST a nice and comfortable button to trigger the test, so good. The code above bugs if the loop time is too high, on my machine 60 seconds it's too high
PS: -People never asked for electricity before its discovery -People can't crave for chocolate if they never tasted or heard of it.
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