∟Calculating Prime Numbers

This section provides a tutorial example on testing performance of an ASP script page doing prime number calculations.

The first area I want to test is integer arithmetic calculations. The following ASP page calculates prime number starting from number 3, and repeats the test many times.

<script language="vbscript" runat="server">
'  prime_numbers.asp
'  Copyright (c) 1999 by Dr. Herong Yang
'  This ASP page calculates prime numbers, and measures its performance.
'
   dim primes(1000)
   numberOfTests = 1
   numberOfPrimes = 1000
   t1 = now
   for nTest = 1 to numberOfTests
      ' Getting prime numbers
      nPrime = 0
      i = 2
      while nPrime < numberOfPrimes
         i = i + 1
         j = 2
         isPrime = true
         while j<i and isPrime
            isPrime = i mod j > 0
            j = j + 1
         wend
         if isPrime then
            nPrime = nPrime + 1
            primes(nPrime) = i
         end if
      wend
   next
   t2 = now
   t = t2 - t1
   
   ' Displaying the results
   response.write("<html><body>")
   response.write("<b>Performance Information</b><br/>")
   response.write("Number of tests = " & numberOfTests & "<br/>")
   response.write("Time = " & _
      Hour(t)&":"&Minute(t)&":"&Second(t) & "<br/>")
   response.write("<b> " & numberOfPrimes & " prime numbers:</b><br/>")
   for n = 1 to numberOfPrimes
      response.write(primes(n) & ", ")
   next 
   response.write("</body></html>")
</script

I run this page, and got the following result. It tells me that the page is working correctly.

Performance Information
Number of tests = 1
Time = 0:0:25
First 1000 Prime numbers:
3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, ...

I repeated the tests by changes the controlling parameters. The following table shows the results comparing with similar tests I did with other technologies:

        Number     Number      Debug   Time
Cases   of Tests   of Primes   Mode    (Sec)   Note

1.      1          1000        Yes     25      ASP with IIS 5.0
2.      1          1000        No      25      ASP with IIS 5.0
3.      1          1000        ?        0      JSP with Tomcat 4.1.18
4.      10         1000        ?        2      JSP with Tomcat 4.1.18
5.      100        1000        ?       22      JSP with Tomcat 4.1.18
6.      100        1000        ?       21      JVM HotSpot 1.3.1

Conclusion:

Table of Contents

 About This Book

 ASP (Active Server Pages) Introduction

 IIS (Internet Information Services) 5.0

 MS Script Debugger

 VBScript Language

 ASP Built-in Run-time Objects

 ASP Session

 Creating and Managing Cookies

 Managing Sessions with and without Cookies

 scrrun.dll - Scripting Runtime DLL

 Managing Response Header Lines

►Calculation Speed and Response Time

►Calculating Prime Numbers

 Response Time of "Hello" Page

 ADO (ActiveX Data Object) DLL

 Working with MS Access Database

 Guest Book Application Example

 References

 Full Version in PDF/EPUB