Performance use procedures and functions have great benefits for the organization and maintenance of code, especially when some of the code in the page needs to be used more than once. However, it is a disadvantage to have a function (or procedure) call to complete the same processing task at this point in time. Theoretically, the variables within the function block are more efficient. Let's take a look at the test results for these two questions.
8.1 Moving the Response.Write statement into the child procedure
In this test, we just put the Response.Write statement into the sub process.
...
Call Writetable ()
SUB writetable ()
Response.Write ("< HTML >" & _
"< head >" & _
...
"< TR >< TD >< B >EMail:</b ></td >< td >" & EMail & "</td ></tr > "& _
"< TR >< TD >< B >birth date:</></td >< td >" & Birthdate & "</td > </tr > "& _
"</table >" & _
"</body >" & _
"End SUB
/app2/function1.asp Fragment
Benchmark = 5.57 MS/page
Response time = 6.02 MS/page
difference = +0.45 milliseconds (increase by 8.1%)
As expected, child process calls add additional page handling burdens.
8.2 Moving all scripts into the child process
In this test, Response.Write and all the variable declarations are moved to the sub process.
<% OPTION EXPLICIT
Call Writetable ()
SUB writetable ()
Dim FirstName
...
Dim Birthdate
FirstName = "John"
...
Birthdate = "1/1/1950"
Response.Write ("< HTML >" & _
"< head >" & _
"< title >response test</title >" & _
""< BODY >" & _
"< H1 >response test
"< table >" & _
"< TR >< TD >< B >first name:</></td >< td >" & FirstName & "</td > </tr > "& _
...
"< TR >< TD >< B >birth date:</></td >< td >" & Birthdate & "</td > </tr > "& _
"</table >" & _
"</body >" & _
"End SUB
/app2/function2.asp Fragment
Benchmark = 5.57 MS/page
Response time = 5.22 MS/page
difference =-0.35 milliseconds (6.3% reduction)
Although there are still additional function calls, putting the variable declaration inside the function actually increases performance beyond the benchmark, which is a noteworthy result! We get the following rules:
If you want to use more than one part of the code in a page, encapsulate them with a function.
If appropriate, move the variable declaration to the function.