Google App Script: identify performance/execution speed bottleneck part of the code. Anyone already succeeded in this in general in terms of techniques? Can you share your examples?
Below is my small script to output HTML webpage with simple table from Google ClassRoom. I'm noob in those technologies as of right now, but trying to make progress in learning.
Maximum 100-150 table rows to output by this script. Could not understand why script runs more than 5-8 minutes to complete its work & eventually output those 100-150 rows HTML table.
Maybe I'm using array wrong way or anything else? Or maybe it is the nature of Google App Script to run slowly overall?
function doGet() {
var res = listCoursesHTML();
var html = HtmlService.createHtmlOutput();
html.append("<table border = \"1\">");
html.append("<tr><th>Имя преподавателя</th><th>Почта</th><th>Название курса</th><th>Название ОП (Учебная группа)</th></tr>");
for(result in res)
{
html.append("<tr><td>"+res[result].Name +"</td><td>"+res[result].email +"</td><td>"+res[result].courseName +"</td><td>" +res[result].courseDescription+"</td></tr>");
}
html.append("</table>");
//return HtmlService.createHtmlOutput(out[0]);
return html;
}
function listCoursesHTML() {
var courses = [];
var ownerId = [];
var pageToken = null;
var optionalArgs = {
pageToken: pageToken,
pageSize: 9999
};
var results = [];
while (true) {
var response = Classroom.Courses.list(optionalArgs);
// @ts-ignore
var courses = response.courses;
if (!pageToken) {
break;
}
}
if (courses.length === 0) {
Logger.log("No courses found.");
} else {
Logger.log("Courses:");
// @ts-ignore
for (course in courses) {
// @ts-ignore
results.push({
"Name": getName(courses[course].ownerId),
"email": getEmail(courses[course].ownerId),
"courseName": courses[course].name,
"courseDescription": courses[course].description
});
}
}
return results;
}
function getEmail(id) {
return Classroom.UserProfiles.get(id).emailAddress;
}
function getName(id) {
return Classroom.UserProfiles.get(id).name.fullName;
}