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?
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.
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.
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...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With