Ask a Question related to ASP.NET General, Design and Development.
-
Andreas Klemt #1
What is faster? DirectCast(myObj, Integer) or Convert.ToInt32(myObj) ???
Hello,
what has the better performance and what are you using?
Dim myObj As Object = 70
a) Dim myInt As Integer = DirectCast(myObj, Integer)
b) Dim myInt As Integer = Convert.ToInt32(myObj)
Thanks,
Andreas
Andreas Klemt Guest
-
#39954 [NEW]: ~ operator doesn't convert string to integer first
From: olafvdspek at gmail dot com Operating system: Windows XP PHP version: 5.2.0 PHP Bug Type: Scripting Engine problem Bug... -
#39278 [NEW]: strpos($needle, $integer) returns 0 for certain values of $integer
From: matt at raines dot me dot uk Operating system: GNU/Linux 2.4.27 PHP version: 5.1.6 PHP Bug Type: Strings related Bug... -
Convert float value to integer
l have a simple question ...l want to convert value from float to interger exemple 5.399 convert to 5 or 5.79 convert to 6 -
Re-convert Currency back to Integer?
Database: Access 2000 How does one switch a converted currency format back to a plain integer in Asp. I have tried Cint but this produces an... -
Do I need to Convert with Convert.ToInt32(session("myNumber")) ?
Hello, I have this session("myNumber") = 888 Dim intNumber As Integer a) intNumber = session("myNumber") b) intNumber =... -
Andreas Klemt #2
Re: What is faster? DirectCast(myObj, Integer) or Convert.ToInt32(myObj) ???
Hello John,
here are my measurements:
Convert.ToInt32 0,37
DirectCast(myObj, Integer) 0,04
Convert.ToString(myObj) 0,42
DirectCast(myObj, String) 0,07
CStr(myObj) 0,50
CType(myObj, String) 0,50
So DirectCast is much faster. What do you use?
Regards,
Andreas
"John Saunders" <john.saunders@surfcontrol.com> schrieb im Newsbeitrag
news:esZacafUDHA.1196@TK2MSFTNGP10.phx.gbl...> I use Option Strict and don't have the problem very often.
>
> DirectCast should be faster in general, since the object _is_ an integer.
>
> To find out whether it's faster in your particular case, why not write a
> little test program which saves the start time, performs the operation
> 100000 times, then compares the start time to the end time? It would allow
> you to test the performance of anything you like.
>
> --
> John Saunders
> Internet Engineer
> [email]john.saunders@surfcontrol.com[/email]
>
> "Andreas Klemt" <aklemt68@hotmail.com> wrote in message
> news:ueVLz7eUDHA.2056@TK2MSFTNGP10.phx.gbl...>> > Hello,
> > what has the better performance and what are you using?
> >
> > Dim myObj As Object = 70
> > a) Dim myInt As Integer = DirectCast(myObj, Integer)
> > b) Dim myInt As Integer = Convert.ToInt32(myObj)
> >
> > Thanks,
> > Andreas
> >
> >
>
Andreas Klemt Guest
-
Karl Seguin #3
Re: What is faster? DirectCast(myObj, Integer) or Convert.ToInt32(myObj) ???
Andreas, how many times do you plan on posting the same question? You've
asked it 4 times since yesterday, always slightly differently..and EACH AND
EVERY TIME someone has provided you with a quality answer.
Did you read "Conversion Functions, CType, DirectCast, and System.Convert"
at
[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchmicrosoftvisualbasicnetinternals.asp[/url]
(as was previously provided)?? It provides a microsoft recommentation as to
which to use...what more could you possibly want?
Karl
"Andreas Klemt" <aklemt68@hotmail.com> wrote in message
news:OTUD1rfUDHA.2076@TK2MSFTNGP11.phx.gbl...integer.> Hello John,
> here are my measurements:
>
> Convert.ToInt32 0,37
> DirectCast(myObj, Integer) 0,04
>
> Convert.ToString(myObj) 0,42
> DirectCast(myObj, String) 0,07
> CStr(myObj) 0,50
> CType(myObj, String) 0,50
>
> So DirectCast is much faster. What do you use?
>
> Regards,
> Andreas
>
>
> "John Saunders" <john.saunders@surfcontrol.com> schrieb im Newsbeitrag
> news:esZacafUDHA.1196@TK2MSFTNGP10.phx.gbl...> > I use Option Strict and don't have the problem very often.
> >
> > DirectCast should be faster in general, since the object _is_ ana> >
> > To find out whether it's faster in your particular case, why not writeallow> > little test program which saves the start time, performs the operation
> > 100000 times, then compares the start time to the end time? It would>> > you to test the performance of anything you like.
> >
> > --
> > John Saunders
> > Internet Engineer
> > [email]john.saunders@surfcontrol.com[/email]
> >
> > "Andreas Klemt" <aklemt68@hotmail.com> wrote in message
> > news:ueVLz7eUDHA.2056@TK2MSFTNGP10.phx.gbl...> >> > > Hello,
> > > what has the better performance and what are you using?
> > >
> > > Dim myObj As Object = 70
> > > a) Dim myInt As Integer = DirectCast(myObj, Integer)
> > > b) Dim myInt As Integer = Convert.ToInt32(myObj)
> > >
> > > Thanks,
> > > Andreas
> > >
> > >
> >
>
Karl Seguin Guest
-
Andreas Klemt #4
Re: What is faster? DirectCast(myObj, Integer) or Convert.ToInt32(myObj) ???
Hello Karl,
I was confused about DirectCast because I never heard about it.
Now after I tested it, everything is clear.
Thanks to you for the link!!
Best Regards,
Andreas
"Karl Seguin" <kseguin##crea.ca> schrieb im Newsbeitrag
news:uQduCwfUDHA.2456@TK2MSFTNGP09.phx.gbl...AND> Andreas, how many times do you plan on posting the same question? You've
> asked it 4 times since yesterday, always slightly differently..and EACH[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchmicrosoftvisualbasicnetinternals.asp[/url]> EVERY TIME someone has provided you with a quality answer.
>
> Did you read "Conversion Functions, CType, DirectCast, and System.Convert"
> at
>to> (as was previously provided)?? It provides a microsoft recommentation aswrite> which to use...what more could you possibly want?
>
> Karl
>
> "Andreas Klemt" <aklemt68@hotmail.com> wrote in message
> news:OTUD1rfUDHA.2076@TK2MSFTNGP11.phx.gbl...> integer.> > Hello John,
> > here are my measurements:
> >
> > Convert.ToInt32 0,37
> > DirectCast(myObj, Integer) 0,04
> >
> > Convert.ToString(myObj) 0,42
> > DirectCast(myObj, String) 0,07
> > CStr(myObj) 0,50
> > CType(myObj, String) 0,50
> >
> > So DirectCast is much faster. What do you use?
> >
> > Regards,
> > Andreas
> >
> >
> > "John Saunders" <john.saunders@surfcontrol.com> schrieb im Newsbeitrag
> > news:esZacafUDHA.1196@TK2MSFTNGP10.phx.gbl...> > > I use Option Strict and don't have the problem very often.
> > >
> > > DirectCast should be faster in general, since the object _is_ an> > >
> > > To find out whether it's faster in your particular case, why not> a> allow> > > little test program which saves the start time, performs the operation
> > > 100000 times, then compares the start time to the end time? It would>> >> > > you to test the performance of anything you like.
> > >
> > > --
> > > John Saunders
> > > Internet Engineer
> > > [email]john.saunders@surfcontrol.com[/email]
> > >
> > > "Andreas Klemt" <aklemt68@hotmail.com> wrote in message
> > > news:ueVLz7eUDHA.2056@TK2MSFTNGP10.phx.gbl...
> > > > Hello,
> > > > what has the better performance and what are you using?
> > > >
> > > > Dim myObj As Object = 70
> > > > a) Dim myInt As Integer = DirectCast(myObj, Integer)
> > > > b) Dim myInt As Integer = Convert.ToInt32(myObj)
> > > >
> > > > Thanks,
> > > > Andreas
> > > >
> > > >
> > >
> > >
> >
>
Andreas Klemt Guest
-
John Saunders #5
Re: What is faster? DirectCast(myObj, Integer) or Convert.ToInt32(myObj) ???
C# :-)
In C#, I use (int) myObj, which is about the same thing as DirectCast.
--
John Saunders
Internet Engineer
[email]john.saunders@surfcontrol.com[/email]
"Andreas Klemt" <aklemt68@hotmail.com> wrote in message
news:OTUD1rfUDHA.2076@TK2MSFTNGP11.phx.gbl...integer.> Hello John,
> here are my measurements:
>
> Convert.ToInt32 0,37
> DirectCast(myObj, Integer) 0,04
>
> Convert.ToString(myObj) 0,42
> DirectCast(myObj, String) 0,07
> CStr(myObj) 0,50
> CType(myObj, String) 0,50
>
> So DirectCast is much faster. What do you use?
>
> Regards,
> Andreas
>
>
> "John Saunders" <john.saunders@surfcontrol.com> schrieb im Newsbeitrag
> news:esZacafUDHA.1196@TK2MSFTNGP10.phx.gbl...> > I use Option Strict and don't have the problem very often.
> >
> > DirectCast should be faster in general, since the object _is_ ana> >
> > To find out whether it's faster in your particular case, why not writeallow> > little test program which saves the start time, performs the operation
> > 100000 times, then compares the start time to the end time? It would>> > you to test the performance of anything you like.
> >
> > --
> > John Saunders
> > Internet Engineer
> > [email]john.saunders@surfcontrol.com[/email]
> >
> > "Andreas Klemt" <aklemt68@hotmail.com> wrote in message
> > news:ueVLz7eUDHA.2056@TK2MSFTNGP10.phx.gbl...> >> > > Hello,
> > > what has the better performance and what are you using?
> > >
> > > Dim myObj As Object = 70
> > > a) Dim myInt As Integer = DirectCast(myObj, Integer)
> > > b) Dim myInt As Integer = Convert.ToInt32(myObj)
> > >
> > > Thanks,
> > > Andreas
> > >
> > >
> >
>
John Saunders Guest



Reply With Quote

