is there any speed diffrences between doing Ctype or directcast? I know
about the inherite diffrences, but process usage time wise, does one take up
more cycles then the other? thanks 7 2639
Brian,
When CType is simply casting I would not expect there to be any speed
difference.
However when CType is converting, then I would expect the process of
converting from one type to a different type to have more overhead then
simply casting. However I question if the difference in speed is worth the
bother.
However! I find its better to write "correct" programs first, then worry
about optimizations after a specific routine has been identified, via
profiling, to have a performance issue.
As you know, CType is the conversion operator used to convert one type into
a different type, such as a String to an Integer. While DirectCast is used
for casting, normally from a base type to a derived type, where the base
object is of the derived type. Where Type can be classes, structures or
interfaces...
Note with overloading the CType operator available in Whidbey (VS.NET 2005
due out next year) it will be even more important to use the "correct"
operator. As a CType that fails in VB.NET 2003 may suddenly work in VB.NET
2005...
Of course "correct-ness" is subjective ;-)
Hope this helps
Jay
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:eU**************@TK2MSFTNGP10.phx.gbl... is there any speed diffrences between doing Ctype or directcast? I know about the inherite diffrences, but process usage time wise, does one take
up more cycles then the other? thanks
I read something recently, I forget where, that stated DirectCast is faster,
but cannot be used in all circumstances.
-- http://www.standards.com/; See Howard Kaikow's web site.
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl... Brian, When CType is simply casting I would not expect there to be any speed difference.
However when CType is converting, then I would expect the process of converting from one type to a different type to have more overhead then simply casting. However I question if the difference in speed is worth the bother.
However! I find its better to write "correct" programs first, then worry about optimizations after a specific routine has been identified, via profiling, to have a performance issue.
As you know, CType is the conversion operator used to convert one type
into a different type, such as a String to an Integer. While DirectCast is used for casting, normally from a base type to a derived type, where the base object is of the derived type. Where Type can be classes, structures or interfaces...
Note with overloading the CType operator available in Whidbey (VS.NET 2005 due out next year) it will be even more important to use the "correct" operator. As a CType that fails in VB.NET 2003 may suddenly work in VB.NET 2005...
Of course "correct-ness" is subjective ;-)
Hope this helps Jay
"Brian Henry" <br**********@newsgroups.nospam> wrote in message news:eU**************@TK2MSFTNGP10.phx.gbl... is there any speed diffrences between doing Ctype or directcast? I know about the inherite diffrences, but process usage time wise, does one
take up more cycles then the other? thanks
Howard,
I believe I stated that in there someplace ;-)
My understanding is that DirectCast will only cast so it is faster, while
CType may convert and this extra check will slow it down.
Realizing that with Option Strict On, the compiler would/should know if
CType needs to cast or convert, so a number of times CType & DirectCast will
be the same speed (produce the same IL code).
However! I don't think it really matters which is faster! IMHO What really
matters is which is correct to use for what you are doing! As you stated,
DirectCast cannot be used in all circumstances, basically it cannot be used
where you need to Convert a value & not cast it!
Hope this helps
Jay
"Howard Kaikow" <ka****@standards.com> wrote in message
news:ee***************@TK2MSFTNGP12.phx.gbl... I read something recently, I forget where, that stated DirectCast is
faster, but cannot be used in all circumstances.
-- http://www.standards.com/; See Howard Kaikow's web site. "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:%2***************@tk2msftngp13.phx.gbl... Brian, When CType is simply casting I would not expect there to be any speed difference.
However when CType is converting, then I would expect the process of converting from one type to a different type to have more overhead then simply casting. However I question if the difference in speed is worth
the bother.
However! I find its better to write "correct" programs first, then worry about optimizations after a specific routine has been identified, via profiling, to have a performance issue.
As you know, CType is the conversion operator used to convert one type into a different type, such as a String to an Integer. While DirectCast is
used for casting, normally from a base type to a derived type, where the base object is of the derived type. Where Type can be classes, structures or interfaces...
Note with overloading the CType operator available in Whidbey (VS.NET
2005 due out next year) it will be even more important to use the "correct" operator. As a CType that fails in VB.NET 2003 may suddenly work in
VB.NET 2005...
Of course "correct-ness" is subjective ;-)
Hope this helps Jay
"Brian Henry" <br**********@newsgroups.nospam> wrote in message news:eU**************@TK2MSFTNGP10.phx.gbl... is there any speed diffrences between doing Ctype or directcast? I
know about the inherite diffrences, but process usage time wise, does one take up more cycles then the other? thanks
thanks everyone
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... Howard, I believe I stated that in there someplace ;-)
My understanding is that DirectCast will only cast so it is faster, while CType may convert and this extra check will slow it down.
Realizing that with Option Strict On, the compiler would/should know if CType needs to cast or convert, so a number of times CType & DirectCast
will be the same speed (produce the same IL code).
However! I don't think it really matters which is faster! IMHO What really matters is which is correct to use for what you are doing! As you stated, DirectCast cannot be used in all circumstances, basically it cannot be
used where you need to Convert a value & not cast it!
Hope this helps Jay
"Howard Kaikow" <ka****@standards.com> wrote in message news:ee***************@TK2MSFTNGP12.phx.gbl... I read something recently, I forget where, that stated DirectCast is faster, but cannot be used in all circumstances.
-- http://www.standards.com/; See Howard Kaikow's web site. "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
message news:%2***************@tk2msftngp13.phx.gbl... Brian, When CType is simply casting I would not expect there to be any speed difference.
However when CType is converting, then I would expect the process of converting from one type to a different type to have more overhead
then simply casting. However I question if the difference in speed is worth the bother.
However! I find its better to write "correct" programs first, then
worry about optimizations after a specific routine has been identified, via profiling, to have a performance issue.
As you know, CType is the conversion operator used to convert one type
into a different type, such as a String to an Integer. While DirectCast is used for casting, normally from a base type to a derived type, where the
base object is of the derived type. Where Type can be classes, structures
or interfaces...
Note with overloading the CType operator available in Whidbey (VS.NET 2005 due out next year) it will be even more important to use the "correct" operator. As a CType that fails in VB.NET 2003 may suddenly work in VB.NET 2005...
Of course "correct-ness" is subjective ;-)
Hope this helps Jay
"Brian Henry" <br**********@newsgroups.nospam> wrote in message news:eU**************@TK2MSFTNGP10.phx.gbl... > is there any speed diffrences between doing Ctype or directcast? I know > about the inherite diffrences, but process usage time wise, does one take up > more cycles then the other? thanks > >
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... Howard, I believe I stated that in there someplace ;-)
I saw the statement in a book or MSDN article, not in any newsgroup.
DirectCast is supposedly faster than CType because it is "more native" to
the .NET Framework. (You would need to have some pretty heavy processing to
notice a difference, though.)
Eric
"Howard Kaikow" <ka****@standards.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Howard, I believe I stated that in there someplace ;-)
I saw the statement in a book or MSDN article, not in any newsgroup.
Howard,
"there" is referring to my post, I believe I made the same statement you
made in my post.
Unfortunately my statement was less succinct then yours ;-)
Jay
"Howard Kaikow" <ka****@standards.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Howard, I believe I stated that in there someplace ;-)
I saw the statement in a book or MSDN article, not in any newsgroup.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Joeri |
last post by:
Hi,
I'm struggling with this issue, maybe someone has already
solved ik before. Here's the problem
I Have :
clsA witch is a base class
clsB inherits from clsA
clsC inherits from clsA
clsD...
|
by: Carl Howarth |
last post by:
Hello there,
I am currently in the process of 'getting strict' with some of our aspx.vb
files. I have a function that is called either when a datarepeater is bound
or when a button on the...
|
by: Mike Cooper |
last post by:
There is something about inherited classes I evidently don't know...
I wrote the following class:
Class Class1
inherits System.Windows.Forms.DataGridTextBoxColumn
End Class
There is...
|
by: Ot |
last post by:
I apparently have a bit to learn about Casting and Conversion. I have been
thinking of them as the same but a discussion in another thread leads me to
believe that this is wrong thinking.
I...
|
by: John A Grandy |
last post by:
could someone please discuss the pros and cons of
CType(MyDouble,Decimal)
versus
Convert.ToDecimal(MyDouble)
.... and other such conversions ...
|
by: Michael Ramey |
last post by:
Hello,
There are quite a few ways to convert one object, say an integer to a
string.
Dim myStr as string
dim myInt as integer = 123
myStr = cstr(myInt)
myStr = myInt.toString()
|
by: iwdu15 |
last post by:
can anyone explain the directcast code...ive tried using it and lookin it up
but im lookin for an easy definition and how it works...ive tried using it
before byut it throws errors saying it can...
|
by: Matt |
last post by:
Does anyone know or care to find out the speed difference between a
directcast call and a direct call?
for instance, i might have these lines of code:
dim j as collections.arraylist
...
|
by: Peter |
last post by:
I have the following code:
_transColl is a collection of classes and it contains about 42000 objects
My question is there any way I can make this code run faster?
I have found out that line 2 is...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |