473,698 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

more efficient - not str1.Equals("xy z") or str1 <> "xyz"?

Hello,

Just checking which is more efficient/better/or correct

Do While something
str1 = dr(i).ToString
If Not str1.Equals("xy z") Then
....

or

If str1 <> "xyz" Then
....

or does it make any difference? or any other syntax?

TIA,
Rich
Nov 20 '05 #1
4 1548
Hi Rich,

This kind of instructions are even when they are a million times in a loop
almost never interesting about efficiency, keep in mind that one show or add
of a visible control can cost you billions more time.

When there was a "better" because of efficiency there would have been not
that much posibilities. So look at good programming where reading for others
is very important before you start optimizing in this part of your program.

I do not like to read statements with str1.Equals("xy z"). That does me think
on languages which no sufficient logical operators and where that has to be
done with methods.

However just a thought,

Cor

Just checking which is more efficient/better/or correct

Do While something
str1 = dr(i).ToString
If Not str1.Equals("xy z") Then
...

or

If str1 <> "xyz" Then
...

or does it make any difference? or any other syntax?

TIA,
Rich

Nov 20 '05 #2
* "Rich" <an*******@disc ussions.microso ft.com> scripsit:
Just checking which is more efficient/better/or correct

Do While something
str1 = dr(i).ToString
If Not str1.Equals("xy z") Then
...

or

If str1 <> "xyz" Then
...

or does it make any difference? or any other syntax?


Call "ILDASM" on the result to see the "difference ".

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Very interesting.

With str1.Equals I get this with "ILDASM":

IL_0029: callvirt instance bool [mscorlib]
System.String:: Equals(string)
If I use st1 <> "xyz" I get this:

IL_002a: call int32 [Microsoft.Visua lBasic]
Microsoft.Visua lBasic.Compiler Services.String Type::StrCmp
(string, string, bool)

It appears from "ILDASM" that str1.Equals is more
efficient overall.

Slowly, I will migrate away from my VB6 habits :).

Thanks,
Rich

-----Original Message-----
* "Rich" <an*******@disc ussions.microso ft.com> scripsit:
Just checking which is more efficient/better/or correct

Do While something
str1 = dr(i).ToString
If Not str1.Equals("xy z") Then
...

or

If str1 <> "xyz" Then
...

or does it make any difference? or any other syntax?


Call "ILDASM" on the result to see the "difference ".

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
.

Nov 20 '05 #4
* "Rich" <an*******@disc ussions.microso ft.com> scripsit:
With str1.Equals I get this with "ILDASM":

IL_0029: callvirt instance bool [mscorlib]
System.String:: Equals(string)
If I use st1 <> "xyz" I get this:

IL_002a: call int32 [Microsoft.Visua lBasic]
Microsoft.Visua lBasic.Compiler Services.String Type::StrCmp
(string, string, bool)

It appears from "ILDASM" that str1.Equals is more
efficient overall.

Slowly, I will migrate away from my VB6 habits :).


I would still use '<>', even if its some ns slower. I am not sure how
'StrCmp' and 'Equals' are implemented, so it's hard to tell which one is
faster.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2046
by: juglesh | last post by:
"$string = isset($xyz) ? $xyz : "something else";" Hello, someone gave code like this in another thread. I understand (by inference) what it does, but have not found any documentation on this type of syntax. Any one have links to this shortuct(?) syntax and other types of
6
2195
by: |-|erc | last post by:
Hi, can a .js file read a parameter into it from the HTML file? this is the code to use in peoples HTML files, each member has their own id. <!-- TopCounters Code START --> <script language="JavaScript" src="http://www.topcounters.com/pphlogger.js?id=johnsmith"> </script>
2
2326
by: Santa | last post by:
Hello: I am trying to manipulating the data from the pointer (the below program) in the function "test1", Is there any best way of changing the data from that pointer (I am changing by assigning the address "&p2->x" to a poiner and then changing. Looklike this is not perfect, can somebody correct me. My programn is below. Thanks, ============================================================== #include <stdio.h>
3
1923
by: Alan LeHun | last post by:
I want to attach a context menu to multiple textboxes but I don't know how the extract the name of the textbox that is the subject of the event. I can't seem to do anything with "sender as system.object" other than get its type. Could someone tell me how to extract this info? I don't like the untidy, inefficient and anti-OO coding of using a seperate context menu for each textbox.
7
19426
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, I need to check if a textbox (of size = 1) contains a specific value (character). I could say something like If txt1.text.equals("X") or txt1.text.equals("Y")... then... Ideally, I would like to do something like Sql --If txt1.text In ("X", "Y", "Z") then...
16
9183
by: network-admin | last post by:
We have Problems with Access query on Oracle 10g Database with ODBC Connection. The Query_1 is such as select * from xtable where ycolumn <"S" Result = ODBC Faild ----------------------------------------------------
20
3552
by: liujiaping | last post by:
I'm confused about the program below: int main(int argc, char* argv) { char str1 = "abc"; char str2 = "abc"; const char str3 = "abc"; const char str4 = "abc"; const char* str5 = "abc";
5
4940
by: .Net Sports | last post by:
I'm having problems trying to get a record out of a resultset when working with a Datalist control. <%# Container.DataItem( "myfield" )%is how I am displaying the field , but when trying to do an If ..then..end if condition and referring to a field in the resultset while inside the <asp:datalist</ asp:datalistenvironment, can't find anything that works. TIA netsports
71
3307
by: Jack | last post by:
I understand that the standard Python distribution is considered the C-Python. Howerver, the current C-Python is really a combination of C and Python implementation. There are about 2000 Python files included in the Windows version of Python distribution. I'm not sure how much of the C-Python is implemented in C but I think the more modules implemented in C, the better performance and lower memory footprint it will get. I wonder if it's...
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9026
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.