Skip to content

Instantly share code, notes, and snippets.

@brainysmurf
Last active June 22, 2021 12:53
Show Gist options
  • Save brainysmurf/0ada72b240d5fd70dd6ef77f913406e9 to your computer and use it in GitHub Desktop.
Save brainysmurf/0ada72b240d5fd70dd6ef77f913406e9 to your computer and use it in GitHub Desktop.
Performance of Endpoins library using fetch requests compared to advanced service.

Motivation

After a few months of using my Endpoints library to help solve myriad of problems in production, I've only had anecdotal evidence that it was a "way more" performant way of interacting with API endpoints, compared to more traditional method of using AppsScripts advanced services. So I decided to actually measure it.

The Test

In my domain, there are 26 google groups, a set for each grade in the school, where a set is one for students and one for parents. We have about 30 students per grade, which means membership of the each students group is about 30, but for the parents, it is twice that (as both parents are a member).

With two different code bases, I download all memberships of all these groups.

  • The code that I test with the Endpoints library interacts with the membership list directory endpoint with UrlFetchApp.fetchAll via batch operations. The library can be found here.
  • The code that I test with the advanced services AdminDirectory.Members.list also interacts with the memberships. It does it one by one, however.

Requirements

Script needs admin directory v1, and corresponding permissions on the domain for the user (beyond this report).

Results

Lower numbers are better.

Iteration 1
admindirectory completed in 4.673 seconds
endpoints_lib completed in 0.441 seconds
Iteration 2
admindirectory completed in 4.548 seconds
endpoints_lib completed in 0.299 seconds
Iteration 3
admindirectory completed in 4.609 seconds
endpoints_lib completed in 0.293 seconds
Iteration 4
admindirectory completed in 4.485 seconds
endpoints_lib completed in 0.304 seconds
Iteration 5
admindirectory completed in 4.353 seconds
endpoints_lib completed in 0.29 seconds
const allGoogGroups_ = () => {
return []; // varies depending on domain
}
function performace_test () {
for (const _ of [1, 2, 4, 5]) {
for (const func of [admindirectory, endpoints_lib]) {
const start = new Date().getTime();
func.call();
const end = new Date().getTime();
Logger.log(`Completed ${func.name} in ${(end - start)/1000} seconds`);
}
}
}
const admindirectory = () => {
for (const group of allGoogGroups_()) {
const _ = AdminDirectory.Members.list(group, {
maxResults: 100,
roles: 'MEMBERS'
});
}
}
const endpoints_lib = () => {
const endpoint = Endpoints.createGoogEndpoint('admin', 'directory_v1', 'members', 'list');
const batch = Endpoints.batch();
for (const group of allGoogGroups_()) {
const request = endpoint.createRequest('get', {groupKey: group}, {
query: {
roles: 'MEMBER', maxResults: 200
}
});
batch.add({request});
}
batch.fetchAll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment