Copy link to clipboard
Copied
Any way to profile performance of JSX layer to find bottlenecks?
I noticed that on Windows 10 my script is running significantly slower than on MacOS.
Still, on both platforms it would be great to profile and find which methods take the longest to run and where are the bottlenecks.
Any tools already available for that?
Copy link to clipboard
Copied
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();
}
}
a = new TimeIt();
...
a.getElapsed();
There is also $.hiresTimer but I've never used it.
Copy link to clipboard
Copied
You can also try
function init_log()
{
_timer_log_ = new Array();
_last_line_ = 1;
$.hiresTimer;
}
function log_delay(l)
{
var time = $.hiresTimer/1000000;
_timer_log_.push([time, "line " + _last_line_ + " to " + l + " \tdelay = " + time.toFixed(3)]);
_last_line_ = l;
}
function show_log()
{
function cmp(a, b) {if (a[0] < b[0]) return 1; if (a[0] > b[0]) return -1; return 0; }
_timer_log_.sort(cmp);
var s = "";
for (var i in _timer_log_) s += _timer_log_[1] +" \n";
alert(s);
}
// example of your script
init_log();
app.activeDocument.channels[0].histogram; //example of your code
log_delay($.line)
app.activeDocument.channels[1].histogram; //example of your code
app.activeDocument.channels[2].histogram; //example of your code
log_delay($.line)
app.activeDocument.histogram; //example of your code
log_delay($.line)
// ...the other part of the code
// log_delay($.line)
// ...the other part of the code
// log_delay($.line)
show_log();
Copy link to clipboard
Copied
The ExtendScript ToolKit (ESTK) has a dedicated profiling tool, that is documented on page 35,36 of the JavaScript Tools Guide.pdf – you should be able to find it in the ESTK own folder.
Davide