473,396 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Minimum time reqd. in calculation ??

A!
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.
Nov 21 '05 #1
5 973
Hi A!,

There is no way we can tell you how to optimize your code when you don't show us the code :P
There is no way we can compare 15 ms to any of our own code either since you don't tell us what system you are running on.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 21 '05 #2
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.

Nov 21 '05 #3
A!
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.


Nov 21 '05 #4
Google for "sieve of erathostenes". I think that should be a lot faster.

Niki

"A!" <an*******@discussions.microsoft.com> wrote in
news:%2****************@TK2MSFTNGP15.phx.gbl...
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.
>
>



Nov 21 '05 #5
Whats StopWatch, is this your code ?, if so post it

--

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****************@TK2MSFTNGP15.phx.gbl...
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.



Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kasp | last post by:
Hi there, I am trying to make an OLAP cube on a table having two columns (datetime, Number_of_times_an_event_occured). My dimension is time and I want to measure the Min and Max times an event...
6
by: A! | last post by:
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...
1
by: Vikrant | last post by:
On my DB2/UDB system, some tablespace 'Minimum recovery time' is 2000-11-19 or some '1999-10-04' or different, for some tablespace theres is no 'Minimum recovery time' , what does it tell me? ...
5
by: Tom | last post by:
A field in a data set I want to import into Access is in Unix time (seconds from a certain time on a certain date). Does anyone know the precise date and the precise time on that date that Unix is...
4
by: Generale Cluster | last post by:
Hello, I need to select the minimum between the result of a function and a number, but i can't find a smart way. By now I'm doing like the following, but I think is very expensive because it...
5
by: Diwa | last post by:
Does the "value" type (value as in key-value pair )of "std::map" require a default ctor even if it is not used ? If I comment out Line 1 in the code attached later, i.e remove the default ctor...
3
by: Frank Rizzo | last post by:
I am trying to do some monitoring of some PerfMon counters and have a question. Does PerfMon figure out the Minimum, Maximum, Average values for each counter? Or are those values part of the...
8
by: Ioannis Vranos | last post by:
About C95. Is there any mentioning in the standard about the number of usable bits of the various built in types, apart from char/signed char/unsigned char types? Or only about the minimum value...
3
by: altafur | last post by:
hi, i am using java with hibernate . i want to run a hibernate order by query thru java. i have written the query in hibernate.hbm.xml file. the query is as follows: query: SELECT distinct...
6
by: anders.johansen | last post by:
Hi, I have a tight loop where I basically do this over and over (millions of times): int cell = <calculation> const int above = <calculation> if (cell above) cell = above; const int below =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.