Here’s a general purpose timer for wrapping functions without having to edit them to put timers around them.

This is something I often have to do if tracking down performance problems, so I thought I’d start to take a look at what Sheets gets up to.

Let’s say you have a function like this you want to time

Certainly you could edit it to put start and finish times around it, but if you are timing a few functions, its better to have a standard way of doing it by proxy.
Using some of the techniques in function ‘currying’, I came up with this as a general timer that can be used to wrap any functions in a timer, execute the function and return the timing information and function results.
It can be used like this.


Having run this a few times, I now know that there is some caching going on with the Spreadsheet service.
Notice that the second pair of results are much shorter than the first (the values from the sheet are cached), and that the second sheet is shorter to get than the first (the spreadsheet object is somehow caching)
timeFunction is available in the cUseful library.
Many of the snippets in this section of the site are part of the cUseful library. You can find the details here.
For more like this see Google Apps Scripts Snippets
Why not join our forum, follow the blog or follow me on Twitter to ensure you get updates when they are available.