Skip to main content
olverart
Inspiring
June 16, 2020
質問

Are scripts slower on new Photoshop versions (2020) than previews versions (2017, 2018, 2019)?

  • June 16, 2020
  • 返信数 2.
  • 515 ビュー

I'm a developer and with the panel / extensions I've been developing, I feel the execution of the scripts are bit slower on newer versions of Photoshop, I've tried all the 2020 versions and goes the same. The scripts are faster on versions from 2017 to 2019. Is there a bug or something? Am I the only one noticing this?

このトピックへの返信は締め切られました。

返信数 2

Inspiring
June 17, 2020

Yes, I have the same feeling, about 10 to 20% slower.

If you want, I found some code a while ago that allows you to time functions and compare the execution time of 2 functions for A/B testing. You could run it in 2017 & in 2019 and compare as JJMack suggested.

 

If you see a significant enough difference, you could refactor some of the heavier code to work with scriptlistener code. Working with ScriptListener code instead of the standard API can speed up execution.

 

 

var Performance = (function() {

	//Sets the amount of executions for the 2 comparePerf functions
	var AB_Performance_ExecutionTimes;

	constructor.prototype.init = function() {
    	AB_Performance_ExecutionTimes = 30; //used while AB testing 2 scripts on their execution speed
    };
   	function constructor() {
		this.init();
	};

//PERFORMANCE TESTING
	/**
	 * Executes a function a set number of times and tracks average execution time
	 * @param  {int}		n Amount of times to execute the function (found in AB_Performance_ExecutionTimes)
	 * @param  {function}	f The function to track
	 * @param  {[parameters]} Optional parameters for the tracked function
	 * @return {number} Returns the execution time of the parameter function in milliseconds
	 */
	constructor.prototype.perf = function(n,f /*optional arguments*/) {
		var args =  Array.prototype.slice.call(arguments, 2);
		var i = (n=n||1), t, r = 0;
			
		while(i--) {
			$.hiresTimer;
			f.apply(null, args);
			t = $.hiresTimer;
			r += t;
		}
		// Clean up
		args.length = 0;
		args = null;
		
		// Average time
		return ~~(r/n);
	};
	/**
	 * Compares the execution time of 2 functions and reports back in Microseconds.
 	 *
	 * SAMPLE CODE:
	 * 		function arrayPush() { ... }
	 * 		function arrayKey() { ... }
	 * 		function arg1(blabla){ ... }
	 * 		function arg2(blabla){ ... }
	 * 		comparePerf(arrayPush, arrayKey);
	 * 		comparePerf(arg1,arg2,"your message");
	 * 		
	 * @param  {function} f1 First function to performance test
	 * @param  {function} f2 Second function to performance test
	 * @return {string} Returns a performance report for the compared functions
	 */
	constructor.prototype.comparePerfInMicroSeconds = function(f1, f2 /*optional arguments*/) {
		var args =  Array.prototype.slice.call(arguments, 2);
		var n = AB_Performance_ExecutionTimes;	
		var t1 = this.perf.apply(null, [n, f1].concat(args));
		var t2 = this.perf.apply(null, [n, f2].concat(args));
		var	r = .1 * ~~(10*(t1/t2));
		
		// Clean up
		args.length = 0;
		args = null;
		
		//prepare return message
		var m = f1.name + "  vs.  " + f2.name + "  -  "+n+" executions\n\n" +
				f1.name + "  executed in on avg :  " + t1 + " \xB5s\n" +
				f2.name + "  executed in on avg :  " + t2 + " \xB5s\n\n";
		if (t1 < t2) {
			m += f1.name + " was faster by a factor of " + r + "\n"; 
		} else if (t1 > t2) {
			m += f2.name + " was faster by a factor of " + r + "\n";
		}
		return (m);
	}
	/**
	 * Compares the execution time of 2 functions and reports back in Seconds.
 	 *
	 * SAMPLE CODE:
	 * 		function arrayPush() { ... }
	 * 		function arrayKey() { ... }
	 * 		function arg1(blabla){ ... }
	 * 		function arg2(blabla){ ... }
	 * 		comparePerf(arrayPush, arrayKey);
	 * 		comparePerf(arg1,arg2,"Roger the blablastring");
	 * 		
	 * @param  {function} f1 First function to performance test
	 * @param  {function} f2 Second function to performance test
	 * @return {string} Returns a performance report for the compared functions
	 */
	constructor.prototype.comparePerfInSeconds = function(f1, f2 /*optional arguments*/) {
		var args =  Array.prototype.slice.call(arguments, 2);
		var n = AB_Performance_ExecutionTimes;	
		var t1 = this.perf.apply(null, [n, f1].concat(args));
		var t2 = this.perf.apply(null, [n, f2].concat(args));
		var	r = .1 * ~~(10*(t1/t2));
		
		// Clean up
		args.length = 0;
		args = null;
		
		//prepare return message
		var m = f1.name + "  vs.  " + f2.name + "  -  "+n+" executions\n\n" +
				f1.name + "  executed in on avg :  " + t1/1000000 + " s\n" +
				f2.name + "  executed in on avg :  " + t2/1000000 + " s\n\n";
		if (t1 < t2) {
			m += f1.name + " was faster by a factor of " + r + "\n"; 
		} else if (t1 > t2) {
			m += f2.name + " was faster by a factor of " + r + "\n";
		}
		return (m);
	}
	/**
	 * Returns the average execution time of a function.
	 * @param  {number} n	Amount of times to run the function 
	 * @param  {function} f	Function to performance test
	 * @return {string} Returns a performance report on the function in microseconds.
	 */
	constructor.prototype.timeFunction = function(n,f /*optional arguments*/) {
		// The sign for micro is expressed as "\xB5"
		return "Function executes in on average "+this.perf(n,f) +" \xB5s";
	};
	return constructor;
})();

 

 

Just copy the code above to a file named "Performance.jsx" and include it in your scripts.

You need to make an instance of it before using it and there are some code samples in the codedocs to help you get started.

 

Hope it helps you out. 🙂

 

Kukurykus
Legend
June 17, 2020

What to exactly do, that I can be given timing result by this code?

JJMack
Community Expert
Community Expert
June 17, 2020

I can not understand his code.  I thought it would be right up your alley for most of the time I can not follow your code for I only hack at JavaScript I know I do not know JavaScript,  Adobe Photoshop DOM or Action Manager code.

 

My Batch script take a long time to process many files.  I don't need any high resolution timer.  The time will very greatly with the number of document and complexity of document.  All I need is a ballpark timer to time the main line code in the scripts show time and number of files processes.  I just used the time of day. Each installation will differ.

 

Time to count to 100,000,000 takes my 2GHZ processors neatly seconds. My wife's machine takes 2 seconds

 

 

startDate = (getDateTime());
var time1 = Number(timeString());
	
for (var m = 0; m < 100000000; m++) { }

var time2 = Number(timeString());
endDate = (getDateTime());
alert(startDate + " Start\n"
	+ "To Count to "  + m + "\n"
	+((time2-time1)/60000 ).toPrecision(5)+" Minutes\n" + endDate + "  End" );    
	
// Function for returning current date and time
function getDateTime() {
    var date = new Date();
    var dateTime = "";
    if ((date.getMonth() + 1) < 10) { dateTime += "0" + (date.getMonth() + 1) + "/"; }
	else { dateTime += (date.getMonth() + 1) + "/"; }
    if (date.getDate() < 10) { dateTime += "0" + date.getDate() + "/"; }
	else { dateTime += date.getDate() + "/"; }
    dateTime += date.getFullYear() + ", ";
    if (date.getHours() < 10) { dateTime += "0" + date.getHours() + ":"; }
	else { dateTime += date.getHours() + ":"; }
    if (date.getMinutes() < 10) { dateTime += "0" + date.getMinutes() + ":"; } 
	else { dateTime += date.getMinutes() + ":"; }
    if (date.getSeconds() < 10) { dateTime += "0" + date.getSeconds(); }
	else { dateTime += date.getSeconds(); }
    return dateTime;
}

function timeString () {
	var now = new Date();
	return now.getTime()
};

 

JJMack
JJMack
Community Expert
Community Expert
June 17, 2020

Try timing them on your your machine using the same image document. If there is a big difference a wall clock will do. Adobe keeps adding thing to Photoshop. Executing path length tend to get longer as new feature are added. 21.2 only seen to have a couple of bug reports file on Adobe feedback site. Considering Adobe Photoshop Update track record that seems good.

 

JJMack