Skip to content

Commit c8e0a0d

Browse files
Aparna SinghAparna Singh
authored andcommitted
Add Execution Time Tracker Script Include snippet
1 parent 93891d6 commit c8e0a0d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
# Script Execution Time Tracker
3+
4+
This snippet helps developers measure how long their server-side scripts take to run in ServiceNow.
5+
Useful for performance optimization and debugging slow background scripts or Script Includes.
6+
7+
## Example Use Case
8+
- Measure performance of a GlideRecord query or function execution.
9+
- Log the execution time to the system logs.
10+
11+
## How It Works
12+
The script uses timestamps before and after execution to measure elapsed time.
13+
14+
## Usage
15+
Wrap your logic between `start` and `stop`, or use the Script Include:
16+
17+
```javascript
18+
var timer = new ExecutionTimeTracker();
19+
// ... your code ...
20+
timer.stop('My Script');
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var ExecutionTimeTracker = Class.create();
2+
ExecutionTimeTracker.prototype = {
3+
initialize: function() {
4+
this.startTime = new Date().getTime();
5+
},
6+
7+
stop: function(label) {
8+
var endTime = new Date().getTime();
9+
var duration = endTime - this.startTime;
10+
gs.info((label || 'Execution') + ' completed in ' + duration + ' ms');
11+
return duration;
12+
},
13+
14+
type: 'ExecutionTimeTracker'
15+
};

0 commit comments

Comments
 (0)