Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling the Performance of a Google App Script

I've written a Google App Script to pull in Google Analytics data into a Google Spreadsheet. It's a fairly long running script making multiple requests to the GA Reporting API, it also uses Google App's ScriptDB.

Is there a good way of profiling each step of the scripts performance so I can figure out what areas are taking the longest, so I can begin optimizing in certain areas?

like image 360
eywu Avatar asked Dec 30 '13 19:12

eywu


People also ask

How do I test a Google app script?

Run a test deployment Open the script project containing your add-on in the script editor. Click Run > Test as add-on. Under Execute Saved Test, find the test to execute and select it. Click Test.

What is VAR in Google script?

The var keyword should only be used when you declare a variable. This only happens once. Once you assign a value to a variable, you can use this value by using the variable's name.


2 Answers

As a complement to Fred's answer, define a variable start at the top of your script

var start = new Date().getTime();

then in a few Logger.log() placed a strategic points use

Logger.log(new Date().getTime()-start);

and you'll get a pretty good idea of what is going on...

like image 200
Serge insas Avatar answered Oct 30 '22 00:10

Serge insas


The Execution Transcript is very useful for this kind of thing.

You can also put Logger.log() statements all over the place that measure the time since the last log. That way you can find areas that take longer to execute.

I have a spreadsheet where I copy the log after an execution and then formulas + conditional formatting help me identify areas that are slow.

like image 36
Fred Avatar answered Oct 29 '22 23:10

Fred