Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# Script Execution Time Tracker

This snippet helps developers measure how long their server-side scripts take to run in ServiceNow.
Useful for performance optimization and debugging slow background scripts or Script Includes.

## Example Use Case
- Measure performance of a GlideRecord query or function execution.
- Log the execution time to the system logs.

## How It Works
The script uses timestamps before and after execution to measure elapsed time.

## Usage
Wrap your logic between `start` and `stop`, or use the Script Include:

```javascript
var timer = new ExecutionTimeTracker();
// ... your code ...
timer.stop('My Script');
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var ExecutionTimeTracker = Class.create();
ExecutionTimeTracker.prototype = {
initialize: function() {
this.startTime = new Date().getTime();
},

stop: function(label) {
var endTime = new Date().getTime();
var duration = endTime - this.startTime;
gs.info((label || 'Execution') + ' completed in ' + duration + ' ms');
return duration;
},

type: 'ExecutionTimeTracker'
};
Loading