Thanks both of you.
Here's my code :
*****************************
Imports System.Math
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Me.SuspendLayout()
Dim i As Int16 = 3
Dim intCounter As Int16 = 2
Dim intDivider As Int16
Dim intRunner As Int16
Dim bolIsPrime As Boolean
Dim arrPrimes(999) As String
arrPrimes(0) = 2
arrPrimes(1) = 3
Dim sw As New StopWatch
Do While Not intCounter > 999
intDivider = Ceiling(Sqrt(i))
If intDivider > 1 Then
For intRunner = 3 To intDivider Step 2
If (i Mod intRunner) = 0 Then
bolIsPrime = False
Exit For
End If
bolIsPrime = True
Next
If bolIsPrime Then
arrPrimes(intCounter) = i
intCounter += 1
End If
End If
i += 2
Loop
'Comment these three lines out when measuring speed of the algo only
ListBox1.BeginUpdate()
ListBox1.Items.AddRange(arrPrimes)
ListBox1.EndUpdate()
Label1.Text = (sw.Peek() / 10).ToString 'Time elapsed.
Me.ResumeLayout()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
End Sub
*****************************
Also, I am running this on a P-4, 512 RAM, 40 GB HDD.
Thanks.
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...
Post your code is a good start
--
OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me
Time flies when you don't know what you're doing
"A!" <an*******@discussions.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Hi all,
I am writing an application in VB.NET to calculate the first 1000 prime
numbers.
The issue is the performance.....I want the time taken to be minimum !
I can achieve this in around 15 milliseconds now.
Is there any way I can cut down this limit to less than a millisecond ?
Please suggest.
TIA.