Apps Script Performance Profiler

Hacky workarounds 101

Ferris Argyle
1 min readAug 24, 2019

As you may have noticed, Apps Script is moving increasingly to a Stackdriver logging model. However, as far as I can tell, the Stackdriver javascript profiler has hard node.js dependencies; corrections in the comments below, would love to be wrong about this.

Yet some scripts take a long time, particularly if they’re add-ons manipulating large Google documents, so a performance profiler is essential to understand where to spend your optimization time.

Following is a quick utility to provide rudimentary profiling information, ie. total duration and number of iterations of each function, as well as detailed durations for each iteration.

To start with, create a spreadsheet which has two sheets with the following columns (you can supplement these with additional calculation columns to the right: these will be preserved); the sheet and column headings are arbitrary, but give you an idea of intent:

  • Raw: Function Name, Part, Line, Time in Milliseconds, Duration
  • Summary: Function Name, Iterations, Total Duration in Milliseconds

Just copy the following lines at the beginning and end of your functions (before the return of course, and before any thrown errors) to invoke the profiler.

And when you’re all done, dump the profile logs to your spreadsheet:

Here’s the full utility:

--

--

Ferris Argyle

These are my personal writings; the views expressed in these pages are mine alone and not those of my employer, Google.