Profiling the Performance of a Google App Script

google apps script wait for response
google script exit function
google script foreach
google script for loop
google apps script slow performance
google script array
google script if
google apps 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?

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.

Apps Script Performance Profiler - Ferris Argyle, 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  13 Profiling the Performance of a Google App Script Dec 30 '13 11 Google Spreadsheet: How can I leave the Script Editor open in another tab after refreshing a spreadsheet Nov 8 '13 11 Google app script timeout ~ 5 minutes?

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...

Why Google Apps Script Is a Great First Programming Language to , This is preposterous -- how could the performance of my scripts vary from one day to the next? Make a Timeline recording and look for suspiciously long Evaluate Script events. If you find any, you can enable the JS Profiler and re-do your recording to get more detailed information about exactly which JS functions were called and how long each took. If you're noticing quite a bit of jank in your JavaScript, you may need to take your

Google Apps Script, Google Spreadsheet and Google Apps Script Professional Indeed, performance and quality are most important aspects of great web Thanks for viewing my profile and feel free to check out my portfolio for my past Google  The Google Apps Script write-back cache helps, because it forces a write-back using flush at the end of every line. Because of the caching, there are only 100 calls to the Spreadsheet. But the code can be made much more efficient by batching the calls.

To correct Serge's answer, where call to Date function has a problem, you can use this solution.

function myFunction() {
  var start_time = new Date().getTime();
  your code goes here
  Logger.log('Total execution time is :' + (new Date().getTime()-start_time) + ' ms');

you can replace the comment lines with your code. After execution press Ctrl + Enter or Command ⌘ + Enter on Mac to see the logs. You will get something like following:

[17-01-18 12:25:58:932 UTC] Total execution time is :16586 ms

So here total execution time is 16586 ms or in other words 16.586 Seconds.

In addition to above you can add the following snippet in between your code to measure execution time from different parts.

Logger.log('Execution time till checkpoint 1:' + (new Date().getTime()-start_time) + ' ms');

Analytics Service | Apps Script, Performance warnings; Allocation call stacks; Editor-only samples Scripts, How much time your application spends on running scripts. Physics, How much  Many Google apps, one platform in the cloud. Increase the power of your favorite Google apps — like Calendar, Docs, Drive, Gmail, Sheets, and Slides. Apps Script lets you do more with Google. All on a JavaScript platform in the cloud.

You should probably use the methods console.time(label) and console.timeEnd(label) since you could get negative results when using Date.

Best Practices | Apps Script, This will create a production build of your app in the build/ folder of your project. Remember <script Profiling Components with the Chrome Performance Tab. The foundation for understanding performance is the RAIL model. This model teaches you the performance metrics that are most important to your users. See Measure Performance With The RAIL Model to learn more. To get more comfortable with the Performance panel, practice makes perfect. Try profiling your own pages and analyzing the results.

Sheets Script Worked Fine for Months, Now Runs , A deep dive into profiling with Google Chrome DevTools and Lighthouse. The Performance tab in Google Chrome DevTools; Lighthouse—an open-source tool for They are the dusty parts of your application and could easily break JavaScript execution time is marked in yellow and it's called Scripting. Optimizing Performance Internally, React uses several clever techniques to minimize the number of costly DOM operations required to update the UI. For many applications, using React will lead to a fast user interface without doing much work to specifically optimize for performance.

27 Best Freelance Google Apps Script Experts For Hire In March , In this scenario, your application and the Cloud Profiler agent run outside the process running the profiling agent, so if you use a script or Dockerfile to run the  Other system wide profiling tools to consider are sysprof and oprofile. It's worth noting that profiling can be problematic on x86_64 at least, due to -fno-omit-frame-pointer being removed to increase performance, and 32 bit fedora at least may be going the same way. Application level profiling. One can use perf to profile a particular command

CPU Usage Profiler module - Unity, Google takes abuse of its services very seriously. We're committed to dealing with such abuse according to the laws in your country of residence. When you submit a report, we'll investigate it and take the appropriate action. We'll get back to you only if we require additional details or have more information to share.

  • please consider my answer as it is : a simple complement about the Logger method. Your solution using SS if of course more convenient although a bit more complex to set up. btw I voted it up :-)
  • OMG, I didn't even know about "Execution Transcript"! Amazing sauce! Also that little spreadsheet you made is awesome! It quickly help me identify the slow down. Thanks!
  • What is wrong on Serge's answer that should be corrected?
  • I have not seen reports of having negative results when using Date on Google Apps Script server side code. Have you seen one?
  • No, I have not seen any either, but I was talking more about the general problem that real world clocks might get synchronized and therefore the resulting difference becomes negative. Though I doubt that this will happen on Google's servers.