Click here to Skip to main content
15,886,037 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Basic looping problem Pin
Mr Oizo6-Feb-09 3:12
Mr Oizo6-Feb-09 3:12 
GeneralRe: Basic looping problem Pin
Guffa6-Feb-09 7:53
Guffa6-Feb-09 7:53 
AnswerRe: Basic looping problem Pin
nlarson116-Feb-09 8:14
nlarson116-Feb-09 8:14 
AnswerRe: Basic looping problem Pin
Guffa7-Feb-09 5:24
Guffa7-Feb-09 5:24 
GeneralRe: Basic looping problem Pin
Samir Ibrahim7-Feb-09 5:49
Samir Ibrahim7-Feb-09 5:49 
GeneralRe: Basic looping problem Pin
Guffa7-Feb-09 8:59
Guffa7-Feb-09 8:59 
GeneralRe: Basic looping problem Pin
Samir Ibrahim10-Feb-09 2:41
Samir Ibrahim10-Feb-09 2:41 
GeneralRe: Basic looping problem Pin
Guffa10-Feb-09 6:43
Guffa10-Feb-09 6:43 
Samir Ibrahim wrote:
That is a clever remark from your side


In what way do you think that it's clever?

Samir Ibrahim wrote:
but my answer is "No Comment"


As in "I'm in to it up to my ears, and in that situation it's best keep your mouth shut"? Wink | ;)

Samir Ibrahim wrote:
because there is to many variables required which is necessary to use the new or old "Now" Value.


That doesn't make sense... What variables are you talking about?

Samir Ibrahim wrote:
- I compare the execution time of both codes
- The result was they are in the same speed until counter "I" is over 1000000 when I is over, CStr is 17 to 30% faster than .ToString
Can you confirm?


Of course not. With as few iterations as you used, you are way below the resolution of the system clock. you should use something that gives a better resolution:
Dim w1 As New Stopwatch, w2 As New Stopwatch
Dim strTemp As String

w1.Start()
For i = 1 To 100000000
	strTemp = CStr(i)
Next i
w1.Stop()

w2.Start()
For i = 1 To 100000000
	strTemp = i.ToString
Next i
w2.Stop()

TextBox1.Text = String.Format("CStr: {0} ms., ToString: {1} ms.", w1.ElapsedMilliseconds, w2.ElapsedMilliseconds)

Result of my test run:

CStr: 12487 ms., ToString: 11406 ms.

According to your test, CStr should be 17-30% faster, but instead ToString is about 9% faster. This is consistent with the code that is generated. If you take a look at the code in .Net Reflector, you see that this statement:

strTemp = CStr(i)

actually compiles into this code:

strTemp = Conversions.ToString(i)

If you look at the Conversions.ToString(Int32) method, it looks like this:
Public Shared Function ToString(ByVal Value As Integer) As String
    Return Value.ToString(Nothing, Nothing)
End Function

If that's not a plain wrapper for the Int32.ToString method, I don't know what is...

Despite everything, the person most likely to be fooling you next is yourself.

GeneralRe: Basic looping problem Pin
Samir Ibrahim10-Feb-09 7:31
Samir Ibrahim10-Feb-09 7:31 
QuestionGroupbox problem Pin
cstrader2326-Feb-09 2:20
cstrader2326-Feb-09 2:20 
AnswerRe: Groupbox problem Pin
JoeSharp6-Feb-09 2:42
JoeSharp6-Feb-09 2:42 
GeneralRe: Groupbox problem Pin
cstrader2326-Feb-09 3:13
cstrader2326-Feb-09 3:13 
GeneralRe: Groupbox problem [modified] Pin
Rekless3-Jan-10 14:00
Rekless3-Jan-10 14:00 
Questionworking with Crystal Report with VB 6 Pin
jayachandra.c6-Feb-09 2:14
jayachandra.c6-Feb-09 2:14 
Questionfile recovery Pin
cst_kvp6-Feb-09 1:52
cst_kvp6-Feb-09 1:52 
AnswerRe: file recovery Pin
EliottA6-Feb-09 2:45
EliottA6-Feb-09 2:45 
GeneralRe: file recovery Pin
Luc Pattyn6-Feb-09 9:30
sitebuilderLuc Pattyn6-Feb-09 9:30 
AnswerRe: file recovery Pin
Dave Kreskowiak6-Feb-09 3:43
mveDave Kreskowiak6-Feb-09 3:43 
AnswerRe: file recovery Pin
0x3c06-Feb-09 8:17
0x3c06-Feb-09 8:17 
QuestionDataGridView selection back color problem Pin
Jay Royall5-Feb-09 23:44
Jay Royall5-Feb-09 23:44 
GeneralGenerating codes for fingerprint security door using VB.Net Pin
awoyale5-Feb-09 22:21
awoyale5-Feb-09 22:21 
GeneralRe: Generating codes for fingerprint security door using VB.Net Pin
Smithers-Jones6-Feb-09 0:24
Smithers-Jones6-Feb-09 0:24 
QuestionCombo Box Frustration Pin
shoorrock5-Feb-09 18:43
shoorrock5-Feb-09 18:43 
AnswerRe: Combo Box Frustration Pin
Christian Graus5-Feb-09 22:06
protectorChristian Graus5-Feb-09 22:06 
Question[Message Deleted] Pin
woca4u5-Feb-09 11:56
woca4u5-Feb-09 11:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.