Hi,
A colleague and I were having a weasely discussion about
which of the following methods is quicker...
Method 1:
var = False
If <cond> Then var = True
Method 2:
If <cond> Then
var = True
Else
var = False
End If
The first is more concise, yet the second is clearer.
Does anyone have anything to contribute to our debate, to
save us taking it outside?!? ;-) 7 1826
You're right: "weasely" is a good term. I doubt a user will ever detect the
difference between these two methods. In a looping situation, I might use
the first method. In any other situation, it will not matter. Use whichever
suits your style.
YMMV,
Bob Barrows
Bobbo wrote: Hi,
A colleague and I were having a weasely discussion about which of the following methods is quicker...
Method 1:
var = False If <cond> Then var = True Method 2:
If <cond> Then var = True Else var = False End If
The first is more concise, yet the second is clearer.
Does anyone have anything to contribute to our debate, to save us taking it outside?!? ;-)
How about :
var = <cond>
:P
Ray at work
"Bobbo" <ro************@yahoonospam.com> wrote in message
news:09****************************@phx.gbl... Hi,
A colleague and I were having a weasely discussion about which of the following methods is quicker...
Method 1:
var = False If <cond> Then var = True Method 2:
If <cond> Then var = True Else var = False End If
The first is more concise, yet the second is clearer.
Does anyone have anything to contribute to our debate, to save us taking it outside?!? ;-)
For those interested, in a 100 million iteration loop,
Method 1 was the quickest (at approx 90% the time of
Method 2).
Incidentally, VB's IIF function was 10 times *slower* than
either of these two!
Right, I've finished being weasely now!
B.
"Bobbo" <ro************@yahoonospam.com> wrote in message
news:0a****************************@phx.gbl... For those interested, in a 100 million iteration loop, Method 1 was the quickest (at approx 90% the time of Method 2).
Incidentally, VB's IIF function was 10 times *slower* than either of these two!
Right, I've finished being weasely now!
B.
Here are my findings:
Method 1: If
Method 2: If..Else
Method 3:Let
True
Method 1: 1.371094
Method 2: 0.9726563
Method 3: 0.7382813
False
Method 1: 0.9101563
Method 2: 0.921875
Method 3: 0.7304688
Mod
Method 1: 2.003906
Method 2: 1.792969
Method 3: 1.191406
I tested three case. Condition false, condition true and condition =
iterator mod 2. The mod 2 condition is important since it covers the
boolean space. In all three cases, Ray's let method was the best
performer. When the condition was true or mod 2, method 2 (if..else)
beat out method 1 (if). Only when the condition was false did method 1
beat out method 2 and then only by a small margin. So if I had to rank
them it would be method 3 (let), method 2 (if..else), method 1 (if).
HTH
-Chris
I don't really think this is what he was looking for though, hence the ":P"
thing. Like, he was probably just using t/f as an example. My guess is
that he was wondering between something more like:
var = "Joe Jones"
If <cond> var = "Mary Jones"
vs.
If <cond> Then
var = "Mary Jones"
Else
var = "Joe Jones"
End If
In that case, I'd probably bet a dollar on the top method.
Ray at work
"Dave Anderson" <GT**********@spammotel.com> wrote in message
news:ua**************@TK2MSFTNGP11.phx.gbl... "Ray at <%=sLocation%>" wrote: How about:
var = <cond> Amen. -- Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms. Please do not
contact me directly or ask me to contact you directly for assistance. If your question is worth asking, it's worth posting.
Actually the 1st structure would be doing 2 string assignments if the
condition is true where the 2nd structure always does a single string
assignment and should be faster overall. That said, I often use the 1st
structure to reduce the nesting level of complex if statements.
---1.a---
var = "Joe Jones"
If False Then var = "Mary Jones"
1,000,000 tries =>3023 ms
---2.a---
If False Then
var = "Mary Jones"
Else
var = "Joe Jones"
End If
1,000,000 tries =>3004 ms
---1.b---
var = "Joe Jones"
If True Then var = "Mary Jones"
1,000,000 tries =>4547 ms
---2.b---
If True Then
var = "Mary Jones"
Else
var = "Joe Jones"
End If
1,000,000 tries =>3145 ms
--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider ms*****@ielearning.com http://www.ielearning.com
714.637.9480 x17
"Ray at <%=sLocation%>" <as*@me.forit> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl... I don't really think this is what he was looking for though, hence the
":P" thing. Like, he was probably just using t/f as an example. My guess is that he was wondering between something more like:
var = "Joe Jones" If <cond> var = "Mary Jones"
vs.
If <cond> Then var = "Mary Jones" Else var = "Joe Jones" End If
In that case, I'd probably bet a dollar on the top method.
Ray at work
"Dave Anderson" <GT**********@spammotel.com> wrote in message news:ua**************@TK2MSFTNGP11.phx.gbl... "Ray at <%=sLocation%>" wrote: How about:
var = <cond>
Amen. -- Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use of this email address implies consent to these terms. Please do not contact me directly or ask me to contact you directly for assistance. If your question is worth asking, it's worth posting.
You are correct!
I ran through each method 10 million times, and got these results:
Method 1:
59 seconds
Method 2:
42 seconds
"Mark Schupp" <ms*****@ielearning.com> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl... Actually the 1st structure would be doing 2 string assignments if the condition is true where the 2nd structure always does a single string assignment and should be faster overall. That said, I often use the 1st structure to reduce the nesting level of complex if statements.
---1.a--- var = "Joe Jones" If False Then var = "Mary Jones" 1,000,000 tries =>3023 ms
---2.a--- If False Then var = "Mary Jones" Else var = "Joe Jones" End If 1,000,000 tries =>3004 ms
---1.b--- var = "Joe Jones" If True Then var = "Mary Jones" 1,000,000 tries =>4547 ms
---2.b--- If True Then var = "Mary Jones" Else var = "Joe Jones" End If 1,000,000 tries =>3145 ms
-- Mark Schupp -- Head of Development Integrity eLearning Online Learning Solutions Provider ms*****@ielearning.com http://www.ielearning.com 714.637.9480 x17
"Ray at <%=sLocation%>" <as*@me.forit> wrote in message news:eX**************@TK2MSFTNGP11.phx.gbl... I don't really think this is what he was looking for though, hence the ":P" thing. Like, he was probably just using t/f as an example. My guess is that he was wondering between something more like:
var = "Joe Jones" If <cond> var = "Mary Jones"
vs.
If <cond> Then var = "Mary Jones" Else var = "Joe Jones" End If
In that case, I'd probably bet a dollar on the top method.
Ray at work
"Dave Anderson" <GT**********@spammotel.com> wrote in message news:ua**************@TK2MSFTNGP11.phx.gbl... "Ray at <%=sLocation%>" wrote: > > How about: > > var = <cond>
Amen. -- Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per
message. Use of this email address implies consent to these terms. Please do not contact me directly or ask me to contact you directly for assistance. If your question is worth asking, it's worth posting.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brian Patterson |
last post by:
I have noticed in the book of words that hasattr works by calling getattr
and raising an exception if no such attribute exists. If I need the value
in any case, am I better off using getattr...
|
by: Michael Andersson |
last post by:
Hi!
Does the use of exception handling induce a performance penalty during
the execution of non exception handling code?
Regards,
/Michael
|
by: Unruled Boy |
last post by:
1.The follow two ways to declare one object: any difference? especially its
performance.
a.Private m_objMyObject As MyObject=New MyObject()
b.Private m_objMyObject As MyObject
m_objMyObject=New...
|
by: Gaurav |
last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250
Any comments?
Thanks
Gaurav
|
by: David W. Fenton |
last post by:
http://www.granite.ab.ca/access/performancefaq.htm
I hope Tony doesn't mind my opening a discussion of some issues on
his performance FAQ page here in the newsgroup. This is not meant as...
|
by: Mark Shelor |
last post by:
I've encountered a troublesome inconsistency in the C-language Perl
extension I've written for CPAN (Digest::SHA). The problem involves the
use of a static array within a performance-critical...
|
by: MSG |
last post by:
Michel Bardiaux <michel.bardiaux@peaktime.be> wrote in message news:<G4idnfgZ0ZfCWbrdRVn2jQ@giganews.com>...
> Mark Shelor wrote:
>
> >
> > OK, Sidney, I am considering it. I can certainly...
|
by: bjarne |
last post by:
Willy Denoyette wrote;
> ... it
> was not the intention of StrousTrup to the achieve the level of efficiency
> of C when he invented C++, ...
Ahmmm. It was my aim to match the performance...
|
by: Tom Jastrzebski |
last post by:
Hello,
I was just testing VB.Net on Framework.Net 2.0 performance when I run into
the this problem.
This trivial code attached below executed hundreds, if not thousand times
faster in VB 6.0...
|
by: Kevin Murphy |
last post by:
I'm using PG 7.4.3 on Mac OS X.
I am disappointed with the performance of queries like 'select foo from
bar where baz in (subquery)', or updates like 'update bar set foo = 2
where baz in...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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,...
| |