Skip to main content
Cyril500
Known Participant
June 15, 2017
Answered

How can I measure the execution time of a Photoshop script?

  • June 15, 2017
  • 3 replies
  • 2390 views

I have several time-consuming Photoshop scripts and want to adjust them. Execution time is a measure of script efficiency for my goals. Hence, I want to measure the execution time of a Photoshop script.  Any help would be highly appreciated.

This topic has been closed for replies.
Correct answer Tom Ruark

var totalTime = new TimeIt();

... do cool stuff ...

totalTime.stop();

// log it out

totalTime.getTime();

function TimeIt() {

  // member variables

  this.startTime = new Date();

  this.endTime = new Date();

  // member functions

  // reset the start time to now

  this.start = function () {

        this.startTime = new Date();

    }

  // reset the end time to now

  this.stop = function () {

        this.endTime = new Date();

    }

  // get the difference in milliseconds between start and stop

  this.getTime = function () {

        return (this.endTime.getTime() - this.startTime.getTime()) / 1000;

    }

  // get the current elapsed time from start to now, this sets the endTime

  this.getElapsed = function () {

        this.endTime = new Date(); return this.getTime();

    }

}

3 replies

Jarda Bereza
Inspiring
June 18, 2017

//reset timer

$.hiresTimer;

//something you want measure

var a = app.activeDocument.artLayers.add();

var b = app.activeDocument.artLayers.add();

var c = app.activeDocument.artLayers.add();

//show message and read time

alert("Time: "+($.hiresTimer/1000000)+"s");

//reset timer beacause we don't want measure how long take click to "OK" button

$.hiresTimer;

//something you want measure

a.remove()

b.remove()

c.remove()

//show message and read time

alert("Time: "+($.hiresTimer/1000000)+"s");

Cyril500
Cyril500Author
Known Participant
June 18, 2017

I want to measure the time of a Photoshop Action... like doAction("ActionName", "ActionSetName");

What strings should I use instead of

var a = app.activeDocument.artLayers.add();

and

a.remove()

Thank you very much for helping me!!!

Jarda Bereza
Inspiring
June 18, 2017

There would be lines of code... something like you wrote. I don't know how to run recorded action.

Jarda Bereza
Inspiring
June 16, 2017

I suggest use high resolution timer or buil-in profiler in extend script toolkit.

$.hiresTimer

reading this timer get time of script execution and it also reset timer. So I suggest do first dummy reading for reseting timer at some point and second reading will show you how much time script spend since first reading.

Cyril500
Cyril500Author
Known Participant
June 18, 2017

Thank you for answering, but I am new to scripting hence I do not understand how and where to use    $.hiresTimer  to solve my issue in Photoshop...

Tom Ruark
Tom RuarkCorrect answer
Inspiring
June 15, 2017

var totalTime = new TimeIt();

... do cool stuff ...

totalTime.stop();

// log it out

totalTime.getTime();

function TimeIt() {

  // member variables

  this.startTime = new Date();

  this.endTime = new Date();

  // member functions

  // reset the start time to now

  this.start = function () {

        this.startTime = new Date();

    }

  // reset the end time to now

  this.stop = function () {

        this.endTime = new Date();

    }

  // get the difference in milliseconds between start and stop

  this.getTime = function () {

        return (this.endTime.getTime() - this.startTime.getTime()) / 1000;

    }

  // get the current elapsed time from start to now, this sets the endTime

  this.getElapsed = function () {

        this.endTime = new Date(); return this.getTime();

    }

}

Cyril500
Cyril500Author
Known Participant
June 15, 2017

Thanks a lot for answering!!! But, sorry for misunderstanding!!! It was my fault when formulating the question! I need a script to measure the execution time of Photoshop Actions. Sorry!!!

Tom Ruark
Inspiring
June 15, 2017

Create a jsx file with the code above.

Replace this line:

... do cool stuff ...

whit this line:

doAction("ActionName", "ActionSetName");

replace the last line with:

alert(totalTime.getTime());