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 4 7241
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" <jo***********@surfcontrol.com> schrieb im Newsbeitrag
news:es**************@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 jo***********@surfcontrol.com
"Andreas Klemt" <ak******@hotmail.com> wrote in message news:ue**************@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, 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 http://msdn.microsoft.com/library/de...tinternals.asp
(as was previously provided)?? It provides a microsoft recommentation as to
which to use...what more could you possibly want?
Karl
"Andreas Klemt" <ak******@hotmail.com> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl... 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" <jo***********@surfcontrol.com> schrieb im Newsbeitrag news:es**************@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 jo***********@surfcontrol.com
"Andreas Klemt" <ak******@hotmail.com> wrote in message news:ue**************@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
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:uQ**************@TK2MSFTNGP09.phx.gbl... 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 http://msdn.microsoft.com/library/de...tinternals.asp (as was previously provided)?? It provides a microsoft recommentation as
to which to use...what more could you possibly want?
Karl
"Andreas Klemt" <ak******@hotmail.com> wrote in message news:OT**************@TK2MSFTNGP11.phx.gbl... 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" <jo***********@surfcontrol.com> schrieb im Newsbeitrag news:es**************@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 jo***********@surfcontrol.com
"Andreas Klemt" <ak******@hotmail.com> wrote in message news:ue**************@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 > >
C# :-)
In C#, I use (int) myObj, which is about the same thing as DirectCast.
--
John Saunders
Internet Engineer jo***********@surfcontrol.com
"Andreas Klemt" <ak******@hotmail.com> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl... 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" <jo***********@surfcontrol.com> schrieb im Newsbeitrag news:es**************@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 jo***********@surfcontrol.com
"Andreas Klemt" <ak******@hotmail.com> wrote in message news:ue**************@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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: cmelnick |
last post by:
I have a custom class that basically consists of two elements, a name
(String) and value (object). I am a bit confused on how to clone or
make a copy of an instance of my object. If I have:
...
|
by: tnhoe |
last post by:
Hi,
<Form method='post' action="next.htm?btn="+"this.myform.myobj.value">
What is the correct syntax for above ?
Regards
Hoe
|
by: opistobranchia |
last post by:
I was on a job interview and the interviewer asked what "this" meant.
I replied it represented this class like cout << a or cout << this.a
then he asked what this meant if it was static?
I...
|
by: Mountain Bikn' Guy |
last post by:
I have a situation where an app writes data of various types (primitives and
objects) into a single dimensional array of objects. (This array eventually
becomes a row in a data table, but that's...
|
by: feng |
last post by:
I need to create cookies in user's machine from my ASP.Net
code and I also need to read them. How do I do that? What
is the API (name space?) for this in APS.Net?
Thanks
|
by: Sam |
last post by:
I have multiple screens during a registration process. I have noticed that
most BIG registration websites are not using "hidden text input objects" to
carry the information from one page to...
|
by: semedao |
last post by:
Hi
I have some Queue object that I enqueue other objects into it.
I want to check if someobject already exists before enqueue , using the
Contains method
but italways return false.
in the object...
|
by: dhtmlkitchen |
last post by:
I think this is not possible...
var fnProto = Function().prototype;
var badAss = { constructor : "Chuck Norris" };
result = ;
function isConstructorEnumerable( ocean, pacific ) {
|
by: Jorge |
last post by:
Why is it listed here :
http://www.crockford.com/javascript/recommend.html
under "deprecation" ?
Without it, how is an anonymous function() going to call itself
(recursively) ?
I use to...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| | |