I have come to greatly respect both Herfried & Cor's reponses and since the
two conflicted, I wanted to get some clarification.
My orginal post:
Herfried, maybe your example here can get you to answer a question I've
wondered about for a while.
With Me.Label1
.Text = ...
.Refresh()
End With
The idea behind the With clause is it allows for faster execution since
the "Me" ojbect doesn't have to be resolved 2 times in your example. But
you could rewrite your sample w/o the Me
With Label1
.Text = ...
.Refresh()
End With
In this case there wouldn't be any inhancement since you are not actually
eliminating the dot. Am I correct in my thinking?
Herfried's response
The 'Me.' is resolved even if it's not explicitly written. In this case I
used With type the code faster ;-).
Cor's Reposnse
The "Me" is only for the programmer, it does nothing at runtime.
The With clause creates an extra reference in a program. In this case it
will be slower than a program without a With clause, however think than
probably in parts of nanoseconds.
I hope this gives some ideas?
Nov 21 '05
27 4710
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote Cor & David, Interesting, if you compile my "benchmark" in the release build & run it outside the IDE (such as from a command prompt). The times are all nearly identical. Which IMHO makes With purely personal prefence (no hurt & no help, use it if it helps you read the code).
Also, if you USE that 'do nothing' code.
A major question I would have is:
How much optimization is being done by the JIT compiler, in that sort of
'minimal' code? Did the JIT compiler resolve the references (providing inline
code perhaps), or are you actually resolving them with your code?
(Yes, the JIT compiler does its own optimizations.. .)
???
LFS
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote I take it you worry more about performant code then "correct" code? By "correct" code I mean a sold OO design which allows easy of maintainability & readibility among other things...
When performance differences are negligible, I tend to be a minimalist. I want
to use only the code necessary to do the job.
OO design, maintainability , readability are IMHO more important driving forces...
I'd order them differently; Readability, conciseness, and then OO design.
If the code is easily read, it will 'generally' also be easy to maintain, and,
OOA is not as important to me as keeping code size down to more managable
sizes. I really liked 'component based' programming (AKA: COM) and to
the effect that objects also include encapsulation, I like those as well.
:-)
LFS
Larry, A major question I would have is:
How much optimization is being done by the JIT compiler, in that sort of 'minimal' code?
Isn't this a Moot or Rhetorical question? If all three perform the same in
Release builds, and differently in Debug, would that not suggest the JIT is
doing some serious optimization?
As you know Debug builds & running under the IDE disable most if not all JIT
optimizations.
(Yes, the JIT compiler does its own optimizations.. .)
I hope you are not impling I do not know that, as that is why I specifically
stated, run the release build outside the IDE!
Hope this helps
Jay
"Larry Serflaten" <se*******@usin ternet.com> wrote in message
news:e5******** ******@tk2msftn gp13.phx.gbl... "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote Cor & David, Interesting, if you compile my "benchmark" in the release build & run it outside the IDE (such as from a command prompt). The times are all nearly identical. Which IMHO makes With purely personal prefence (no hurt & no help, use it if it helps you read the code).
Also, if you USE that 'do nothing' code.
A major question I would have is:
How much optimization is being done by the JIT compiler, in that sort of 'minimal' code? Did the JIT compiler resolve the references (providing inline code perhaps), or are you actually resolving them with your code? (Yes, the JIT compiler does its own optimizations.. .)
??? LFS
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:O2******** ******@TK2MSFTN GP15.phx.gbl... David, With VB.NET this is no longer the case, and most realistic VB code can't be substantially improved by WITH. Which I hope you will agree is what I stated in my reply to Cor.
I also hope you will agree, even under VB5 & VB6 in your simply example there would be no real performance benefit.
Absolutely. VBScript performance used to really matter because of Microsoft
Access and then because of ASP. Only then was WITH even on the performance
radar.
And I believe that in VBScript
with obj
.foo
.foo
end with
was faster than
obj.foo
obj.foo
because the runtime type of obj only had to be discovered once.
David
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote How much optimization is being done by the JIT compiler, in that sort of 'minimal' code?
Isn't this a Moot or Rhetorical question? If all three perform the same in Release builds, and differently in Debug, would that not suggest the JIT is doing some serious optimization?
Quite so, which is why I wondered how you could conclude that With usage was
purely personal preference related, opposed to deducing that perhaps, the code
used was not diverse enough to show where With is a benefit:
The times are all nearly identical. Which IMHO makes With purely personal prefence (no hurt & no help, use it if it helps you read the code).
Perhaps using With on an external object, where JIT optimizations would not
apply, might be a better example for profiling?
(Yes, the JIT compiler does its own optimizations.. .) I hope you are not impling I do not know that
No, that was a parenthetical inclusion for everyone else who may be
reading the thread....
LFS
David, because the runtime type of obj only had to be discovered once.
I would hope it does, Its been too long since I used VBScript...
VBScript performance used to really matter because of Microsoft Access and then because of ASP.
Microsoft Access uses VBA not VBScript. Access started out with Access Basic
ASP & Outlook use VBScript.
Thanks for the info
Jay
"David Browne" <davidbaxterbro wne no potted me**@hotmail.co m> wrote in
message news:%2******** ********@TK2MSF TNGP15.phx.gbl. .. "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:O2******** ******@TK2MSFTN GP15.phx.gbl... David, With VB.NET this is no longer the case, and most realistic VB code can't be substantially improved by WITH. Which I hope you will agree is what I stated in my reply to Cor.
I also hope you will agree, even under VB5 & VB6 in your simply example there would be no real performance benefit.
Absolutely. VBScript performance used to really matter because of Microsoft Access and then because of ASP. Only then was WITH even on the performance radar.
And I believe that in VBScript with obj .foo .foo end with
was faster than obj.foo obj.foo
because the runtime type of obj only had to be discovered once.
David
Larry, Perhaps using With on an external object, where JIT optimizations would not apply, might be a better example for profiling?
I'm sorry I believe you missed the reason for the sample in an earlier post
of mine:
<quote>
Of course the above test was designed to prove the point that With will help
performance with some code. In the original questions case I think its
largely a moot point, there With is "purely" personal preference.
</quote>
The sample I did intentionally shows that using With is a personal
preference, it was to disprove the statement.
<quote>
Your notion that WITH helps with performance by reducting object
resolutions is obsolete.
</quote>
As we all know a number of benchmarks are generally designed to prove a
point. Personally you need to profile actual specific code (not create a
"better example") to decide if the code fits or does not fit a routine.
(hint the 80/20 rule).
Hope this helps
Jay
"Larry Serflaten" <se*******@usin ternet.com> wrote in message
news:ur******** ********@TK2MSF TNGP11.phx.gbl. .. "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote
> How much optimization is being done by the JIT compiler, in that sort > of > 'minimal' code? Isn't this a Moot or Rhetorical question? If all three perform the same in Release builds, and differently in Debug, would that not suggest the JIT is doing some serious optimization?
Quite so, which is why I wondered how you could conclude that With usage was purely personal preference related, opposed to deducing that perhaps, the code used was not diverse enough to show where With is a benefit: > The times are all nearly identical. Which IMHO makes With purely > personal > prefence (no hurt & no help, use it if it helps you read the code). Perhaps using With on an external object, where JIT optimizations would not apply, might be a better example for profiling?
> (Yes, the JIT compiler does its own optimizations.. .) I hope you are not impling I do not know that
No, that was a parenthetical inclusion for everyone else who may be reading the thread....
LFS
Jay,
I tested it, outside the IDE and inside. Outside : inside the IDE is about
1:1,5 for all except the part without "with" which is inside the IDE 2 times
slower than the other ones.
After that you have explained what is this code beneath in your code, than I
thank you for supplying this test to us, now we can point next time to that
test when the question comes again. Return
Application.Ena bleVisualStyles () Application.DoE vents() Application.Run (New MainForm)
Cor
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> Cor & David, Interesting, if you compile my "benchmark" in the release build & run it outside the IDE (such as from a command prompt). The times are all nearly identical. Which IMHO makes With purely personal prefence (no hurt & no help, use it if it helps you read the code).
Try the following in a Console application, where WithTests is the startup module: Run it both in Debug & Release builds, run it both from the IDE & from a command line...
Option Strict On Option Explicit On
Public Class WithTests
Class Base Public ReadOnly class1 As New class1 End Class
Class Class1 Public ReadOnly class2 As New class2 End Class
Class Class2 Public ReadOnly class3 As New class3 End Class
Class Class3 Public ReadOnly class4 As New class4 End Class
Class Class4 Public ReadOnly class5 As New class5 End Class
Class Class5 Public value1 As Integer Public value2 As Integer Public value3 As Integer End Class
Declare Function QueryPerformanc eCounter Lib "Kernel32" (ByRef X As Long) As Short Declare Function QueryPerformanc eFrequency Lib "Kernel32" (ByRef X As Long) As Short
Private Shared Sub WriteTotal(ByVa l start As Long, ByVal finish As Long, ByVal frequency As Long, ByVal category As String) Const format As String = " {0}: elapsed={1}, seconds={2}" Console.WriteLi ne(format, category, (finish - start), TimeSpan.FromSe conds((finish - start) / frequency)) End Sub
Public Shared Sub Main() Const format As String = "Test: {0}" Const MaxIterations As Integer = 100000000 Dim a As New Base Dim start, finish As Long Dim frequency As Long QueryPerformanc eFrequency(freq uency)
For test As Integer = 1 To 5 Console.WriteLi ne(format, test) QueryPerformanc eCounter(start) For count As Integer = 1 To MaxIterations TestWith(a) Next QueryPerformanc eCounter(finish ) WriteTotal(star t, finish, frequency, "with")
QueryPerformanc eCounter(start) For count As Integer = 1 To MaxIterations TestWithout(a) Next QueryPerformanc eCounter(finish ) WriteTotal(star t, finish, frequency, "with out")
QueryPerformanc eCounter(start) For count As Integer = 1 To MaxIterations TestLocal(a) Next QueryPerformanc eCounter(finish ) WriteTotal(star t, finish, frequency, "local")
Console.WriteLi ne() Next Return
Application.Ena bleVisualStyles () Application.DoE vents() Application.Run (New MainForm) End Sub
Public Shared Sub TestWith(ByVal a As Base) With a.class1.class2 .class3.class4. class5 .value1 = 1 .value2 = 2 .value3 = 3 End With End Sub
Public Shared Sub TestWithout(ByV al a As Base) a.class1.class2 .class3.class4. class5.value1 = 1 a.class1.class2 .class3.class4. class5.value2 = 2 a.class1.class2 .class3.class4. class5.value3 = 3 End Sub
Public Shared Sub TestLocal(ByVal a As Base) Dim c5 As Class5 = a.class1.class2 .class3.class4. class5 c5.value1 = 1 c5.value2 = 2 c5.value3 = 3 c5 = Nothing End Sub
End Class
Results on my computer: Test: 1 with: elapsed=8950281 , seconds=00:00:0 2.5000000 with out: elapsed=8595814 , seconds=00:00:0 2.4010000 local: elapsed=8918192 , seconds=00:00:0 2.4910000
Test: 2 with: elapsed=8613901 , seconds=00:00:0 2.4060000 with out: elapsed=8615269 , seconds=00:00:0 2.4070000 local: elapsed=8781567 , seconds=00:00:0 2.4530000
Test: 3 with: elapsed=9588239 , seconds=00:00:0 2.6790000 with out: elapsed=1120392 5, seconds=00:00:0 3.1300000 local: elapsed=1047161 4, seconds=00:00:0 2.9250000
Test: 4 with: elapsed=8614997 , seconds=00:00:0 2.4070000 with out: elapsed=8615433 , seconds=00:00:0 2.4070000 local: elapsed=8778982 , seconds=00:00:0 2.4530000
Test: 5 with: elapsed=8675226 , seconds=00:00:0 2.4240000 with out: elapsed=8610307 , seconds=00:00:0 2.4050000 local: elapsed=8558526 , seconds=00:00:0 2.3910000
Hope this helps Jay "Cor Ligthert" <no************ @planet.nl> wrote in message news:uZ******** ******@TK2MSFTN GP14.phx.gbl... Jay,
The With clause creates an extra reference in a program. In this case it will be slower than a program without a With clause, however think than probably in parts of nanoseconds.
Are you quoting Cor correctly? With will normally increases not decreases speed. Yes it creates a temporary variable, but that shouldn't really matter.
Yes Chris is, look at "In this case", see for the rest as Samuel wrote and my reply on that.
Cor
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dave |
last post by:
I have 2 tables, one with names, and another with addresses, joined by their
CIVICID number (unique to the ADDRESSINFO table) in Oracle.
I need to update a field in the NAMEINFO table for a particular surname in a
particular town.
I can select the records fine with this syntax (testing in Oracle SQL* Plus)
SELECT NAMEINFO.LASTNAME, NAMEINFO.FIRSTNAME, NAMEINFO.MIDDLENAME,
NAMEINFO.GENDER, ADDRESSINFO.REGION FROM NAMEINFO, ADDRESSINFO...
|
by: Steven An |
last post by:
Howdy,
I need to write an update query with multiple aggregate functions.
Here is an example:
UPDATE t
SET
t.a = ( select avg(f.q) from dbo.foo f where f.p = t.y ),
t.b = ( select sum(f.q) from dbo.foo f where f.p = t.y )
FROM dbo.test t
|
by: Jerry |
last post by:
Well, here is some weirdness. First, I noticed that I
have 2 Set keywords (silly me). so I removed the
2nd "Set" but still got a syntax error. Then I removed
the Where clause, and now it works perfectly. Is this
correct? Or am I just getting lucky? I'm not completely
clear on the fundamentals here. I update the table in my
dataset, then I update the table on the server through the
dataAdapter. I think I have a handle on the...
|
by: Brian Tkatch |
last post by:
An ORDER BY a simple-integer inside a FUNCTION, results in SQL0440N,
unless the FUNCTION expects an INTEGER as its parameter. For example:
DECLARE GLOBAL TEMPORARY TABLE A(A CHAR(1))
INSERT INTO SESSION.A VALUES ('a'), ('b')
CREATE FUNCTION A(A char(1)) RETURNS char(1) DETERMINISTIC NO EXTERNAL
ACTION RETURN A
SELECT A FROM SESSION.A ORDER BY A(1)
DROP FUNCTION A
DROP TABLE SESSION.A
|
by: GreatAlterEgo |
last post by:
Hi,
This is my query which is embedded in a COBOL program.
EXEC SQL
SELECT DATE, AGE, DURATION, AMT
INTO :LDATE, :L.AGE, :L.DURATION, :L.AMT
FROM TAB1
WHERE CODE = :KEY.CODE
AND SET = :KEY.SET
AND DATE <= :KEY.DATE
| |
by: rcamarda |
last post by:
I have a field that may be null which is valid, and I am finding
something I didnt expect when working with nulls.
SELECT NULL/4.0 will return NULL (which I expect), however, when I test
it with a case it does not:
SELECT NULL/4.0 AS 'TEST1', TEST2 = CASE NULL/4.0 WHEN NULL THEN
'HURAY' ELSE 'OH DARN' END
I can work around by testing for NULL first else CASE ..., but I'd like
to understand why the CASE does not test for null.
|
by: Jobs |
last post by:
Download the JAVA , .NET and SQL Server interview with answers
Download the JAVA , .NET and SQL Server interview sheet and rate
yourself. This will help you judge yourself are you really worth of
attending interviews. If you own a company best way to judge if the
candidate is worth of it.
http://www.questpond.com/InterviewRatingSheet.zip
|
by: rogynskyy |
last post by:
Hi guys,
I'm running MSDE 2000 A on Win XP
I've got a database with several tables, all of the tables display data in query manager.
I wrote this simple query:
Select
|
by: Sascha.Moellering |
last post by:
Hi,
I receive the error code SQL0338N if I try to compile this statement
(part of the statement):
.... left outer join lateral
(SELECT * FROM LIZSYSABA.VWZL0359TBS WHERE tbs_name = CASE WHEN
MC.type_txt = 'ZAB' THEN 'BII' ELSE 'STD' END) AS TB1
on CASE WHEN MC.fixed_date_dat IS NULL THEN cast('01.01.2007' as date)
+ MC.rel_shift_NR DAY ELSE MC.fixed_date_dat END
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |