Skip to content

Instantly share code, notes, and snippets.

@derkzomer
Created April 3, 2023 02:52
Show Gist options
  • Save derkzomer/e01f1f3b4c99e3aaab2aef906115f858 to your computer and use it in GitHub Desktop.
Save derkzomer/e01f1f3b4c99e3aaab2aef906115f858 to your computer and use it in GitHub Desktop.
// Average render times in milliseconds
const renderTimes = {
hd: 30500,
sd: 8500,
'1080': 38500,
};
// Function to calculate the percentage of time elapsed
function getRenderPercentage(resolution, elapsedTime) {
// Check if the given resolution is valid
if (!renderTimes.hasOwnProperty(resolution)) {
throw new Error(`Invalid resolution: ${resolution}`);
}
// Calculate the percentage
const percentage = (elapsedTime / renderTimes[resolution]) * 100;
// Make sure the percentage is between 0 and 100
return Math.min(Math.max(percentage, 0), 100);
}
// Example usage
let elapsedTime = 0;
const resolution = 'hd'; // Change this to the desired resolution
const interval = setInterval(() => {
elapsedTime += 1000; // Increment elapsed time by 1 second (1000ms)
const percentage = getRenderPercentage(resolution, elapsedTime);
console.log(`Time elapsed: ${elapsedTime}ms, Render percentage: ${percentage.toFixed(2)}%`);
// Stop the interval when the render is estimated to be complete
if (percentage >= 100) {
clearInterval(interval);
console.log('Render estimated to be complete.');
}
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment