Skip to content

Instantly share code, notes, and snippets.

@VehpuS
Created August 21, 2025 16:20
Show Gist options
  • Select an option

  • Save VehpuS/ef2f3c97aa1156b42fb76a1cf911cdae to your computer and use it in GitHub Desktop.

Select an option

Save VehpuS/ef2f3c97aa1156b42fb76a1cf911cdae to your computer and use it in GitHub Desktop.
Decorate library class methods with timers
function withTimer(func: (...args: any[]) => any, userDefinedName?: string): (...args: any[]) => any {
const functionName = userDefinedName || func.name || 'unknown';
console.log('Decorator applied to:', functionName);
return function (...args) {
const start = performance.now(); // Get high-resolution time before execution
const result = func.apply(this, args);
//func(...args); // Execute the original function
const end = performance.now(); // Get high-resolution time after execution
const duration = end - start; // Calculate the duration
console.log(`Function '${functionName}' executed in ${duration.toFixed(2)} ms.`);
return result;
};
}
// i.e. GeoJsonLayer.prototype.updateState = withTimer(GeoJsonLayer.prototype.updateState, `updateState`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment