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 7243
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: 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: 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: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
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)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| | |