Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'outside the loop
Dim bNeedsColor
bNeedsColor = True
'inside the loop
If bNeedsColor Then
bgcolor = "#FFFFCC"
Else
bgcolor = "#FFFFFF"
End If
bNeedsColor = Not bNeedsColor
<style>
.even{ color: black; background-color: white;}
.oneven{ COLOR: white; BACKGROUND-COLOR: black;}
</style>
<h1>INT(i/2)=i/2</h1>
<%
dim start
start = timer
response.Write "<table>"
dim i
for i = 1 to 100000
if i/2 = int(i/2) then
response.Write "<tr class=even>"
else
response.Write "<tr class=oneven>"
end if
response.Write "<td>test</td></tr>"
next
response.Write "<table>"
response.Write "Time: " & timer - start
%>
<style>
.even{ color: black; background-color: white;}
.oneven{ COLOR: white; BACKGROUND-COLOR: black;}
</style>
<h1>STRING COMPARISON</h1>
<%
dim start
start = timer
response.Write "<table>"
dim c
c = "even"
for i = 1 to 100000
if c = "oneven" then
response.Write "<tr class=even>"
c = "even"
else
response.Write "<tr class=oneven>"
c = "oneven"
end if
response.Write "<td>test</td></tr>"
next
response.Write "<table>"
response.Write "Time: " & timer - start
%>
<style>
.even{color: black; background-color: white;}
.oneven{COLOR: white; BACKGROUND-COLOR: black;}
</style>
<h1>i MOD 2</h1>
<%
dim start
start = timer
response.Write "<table>"
dim i
for i = 1 to 100000
if (i mod 2) = 0 then
response.Write "<tr class=even>"
else
response.Write "<tr class=oneven>"
end if
response.Write "<td>test</td></tr>"
next
response.Write "<table>"
response.Write "Time: " & timer - start
%>
<style>
.even{ color: black; background-color: white;}
.oneven{ COLOR: white; BACKGROUND-COLOR: black;}
</style>
<h1>B = NOT B</h1>
<%
dim start
start = timer
response.Write "<table>"
dim b
b = true
for i = 1 to 100000
if b then
response.Write "<tr class=even>"
else
response.Write "<tr class=oneven>"
end if
b = not b
response.Write "<td>test</td></tr>"
next
response.Write "<table>"
response.Write "Time: " & timer - start
%>
<%
'------------------------------------------------
' Alternating Row Benchmark
' Written March 07, 03 based on tests written by Foxbox (tek-Tips.com)
' Tarwn
'------------------------------------------------
'
' Method 1: If Int(i/2) = 1/2 Then
' Method 2: String Comparison
' Method 3: String comparison with concatenation
' Method 4: If i Mod 2 = 0 Then
' Method 5: Mod concatenated for class name
' Method 6: If B = Not B Then
'------------------------------------------------
' Contents will be Response.Cleared afterwards so
' we don't have to deal with the browser output.
' This should not make a difference in the timer
' outcome.
Dim m_time(6)
Dim m_avg(6), m_low(6), m_high(6)
Dim m_title(6)
Dim s_time
m_title(1) = "INT(i/2)=i/2"
m_title(2) = "STRING COMPARISON"
m_title(3) = "STRING COMPARISON W/ Concatenation"
m_title(4) = "i MOD 2"
m_title(5) = "i MOD 2 With class name concatenation"
m_title(6) = "B = Not B"
'------------------ Workhorse -------------------
' Runs te test code and displays results
Dim num_tests, num_runs
num_tests = 500000
num_runs = 4
Dim run_counter, method_counter
'initialize low, high, total time values
For method_counter = 1 to 6
m_time(method_counter) = 0
m_low(method_counter) = 100000
m_high(method_counter) = 0
Next
'run the tests
Dim temp_time
For run_counter = 1 to num_runs
For method_counter = 1 to 6
temp_time = Runtest(method_counter, num_tests) 'get test results
If temp_time = -1 Then
Response.Write "Error Occurred: mc=" & method_counter & " rc=" & run_counter
Response.End
End If
m_time(method_counter) = m_time(method_counter) + temp_time 'add time to total time for this method
If temp_time < m_low(method_counter) Then m_low(method_counter) = temp_time 'if this is lowest, substitute
If temp_time > m_high(method_counter) Then m_high(method_counter) = temp_time 'if this is highest, substitute
If run_counter = num_runs Then m_avg(method_counter) = m_time(method_counter)/num_runs 'if last run then calc average
temp_time = -1 'insurance on next loop
Next
Next
Response.Write "<table style=""display:inline;""><tr><th colspan=""3"">Benchmark Results</th></tr>"
Response.Write "<tr><th>Method</th><th>Name</th><th>Average</th><th>Low</th><th>High</th></tr>"
For method_counter = 1 to 6
Response.Write "<tr><td>Method #" & method_counter & "</td><td>" & m_title(method_counter) & "</td><td>" & FormatNumber(m_avg(method_counter),3) & "</td><td>" & FormatNumber(m_low(method_counter),3) & "</td><td>" & FormatNumber(m_high(method_counter),3) & "</td></tr>"
Next
Response.Write "</table><br>"
Response.Write "Times are averages from " & num_runs & " runs of " & num_tests & " loops for each method."
'------------------ Test Functions --------------
' These are the functions to handle the actual 6
' method tests
Function Method1(tCount)
StartClock
%>
<style>
.even{ color: black; background-color: white;}
.oneven{ COLOR: white; BACKGROUND-COLOR: black;}
</style>
<h1>INT(i/2)=i/2</h1>
<%
response.Write "<table>"
dim i
for i = 1 to tCount
if i/2 = int(i/2) then
response.Write "<tr class=even>"
else
response.Write "<tr class=oneven>"
end if
response.Write "<td>test</td></tr>"
next
response.Write "<table>"
Method1 = StopClock
Response.Clear
End Function
Function Method2(tCount)
StartClock
%>
<style>
.even{ color: black; background-color: white;}
.oneven{ COLOR: white; BACKGROUND-COLOR: black;}
</style>
<h1>STRING COMPARISON</h1>
<%
response.Write "<table>"
dim c
c = "even"
for i = 1 to tCount
if c = "oneven" then
response.Write "<tr class=even>"
c = "even"
else
response.Write "<tr class=oneven>"
c = "oneven"
end if
response.Write "<td>test</td></tr>"
next
response.Write "<table>"
Method2 = StopClock
Response.Clear
End Function
Function Method3(tCount)
StartClock
%>
<style>
.even{ color: black; background-color: white;}
.oneven{ COLOR: white; BACKGROUND-COLOR: black;}
</style>
<h1>STRING COMPARISON W/ Concatenation</h1>
<%
response.Write "<table>"
dim c
c = "even"
for i = 1 to tCount
Response.Write "<tr class=" & c & ">"
if c = "oneven" then c = "even" else c = "oneven"
response.Write "<td>test</td></tr>"
next
response.Write "<table>"
Method3 = StopClock
Response.Clear
End Function
Function Method4(tCount)
StartClock
%>
<style>
.even{color: black; background-color: white;}
.oneven{COLOR: white; BACKGROUND-COLOR: black;}
</style>
<h1>i MOD 2</h1>
<%
response.Write "<table>"
dim i
for i = 1 to tCount
if (i mod 2) = 0 then
response.Write "<tr class=even>"
else
response.Write "<tr class=oneven>"
end if
response.Write "<td>test</td></tr>"
next
response.Write "<table>"
Method4 = StopClock
Response.Clear
End Function
Function Method5(tCount)
StartClock
%>
<style>
.row_0{color: black; background-color: white;}
.row_1{COLOR: white; BACKGROUND-COLOR: black;}
</style>
<h1>i MOD 2 as style class</h1>
<%
response.Write "<table>"
dim i
for i = 1 to tCount
Response.Write "<tr class=row_" & i mod 2 & ">"
response.Write "<td>test</td></tr>"
next
response.Write "<table>"
Method5 = StopClock
Response.Clear
End Function
Function Method6(tCount)
StartClock
%>
<style>
.even{ color: black; background-color: white;}
.oneven{ COLOR: white; BACKGROUND-COLOR: black;}
</style>
<h1>B = NOT B</h1>
<%
response.Write "<table>"
dim b
b = true
for i = 1 to tCount
if b then
response.Write "<tr class=even>"
else
response.Write "<tr class=oneven>"
end if
b = not b
response.Write "<td>test</td></tr>"
next
response.Write "<table>"
Method6 = StopClock
Response.Clear
End Function
'------------------ Clock Functions -------------
' Usually these would be in a language that has
' better millisecond resolution, but shouldn't
' be necessary in this case
Function StartClock()
s_time = timer
End Function
Function StopClock()
StopClock = timer - s_time
End Function
'------------------ RunTest Function ------------
' Allows us to make one call and run any test
Function RunTest(testNum, loopCount)
Select Case testNum
Case "1"
Runtest = Method1(loopCount)
Case "2"
Runtest = Method2(loopCount)
Case "3"
Runtest = Method3(loopCount)
Case "4"
Runtest = Method4(loopCount)
Case "5"
Runtest = Method5(loopCount)
Case "6"
Runtest = Method6(loopCount)
Case Else
Runtest = -1
End Select
End Function
%>