Created
August 21, 2025 16:20
-
-
Save VehpuS/ef2f3c97aa1156b42fb76a1cf911cdae to your computer and use it in GitHub Desktop.
Decorate library class methods with timers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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