473,484 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Code Efficiency

675 Contributor
Efficiency

I've never stumbled on any discussion of efficiency of various methods of coding, although I have found posts on various forums where individuals were concerned with efficiency. I'm not concerned when dealing with user typing, but I am if a procedure is called by a query.

Does the VBA compiler generate "in-line" code for some apparent function calls? For example, y = Abs(x) might be compiled as y = x & mask. The string functions Left, Right, and Mid might also be compiled into compact code, and not be functions at all. Seems like y = x and y = Left(x, 4) might compile to Move Addrss x, Lenth = Len(x) to Address y or Move Address x, Length = 4 to Address y. No time/efficiency difference.

Second efficiency question. I have a table with 100K records, one field is "Selected", a boolean field. To clear all selected items, I run an update query. Which is better? If one is better, where is the break point. Obviously if Selected is 99% of the table size, it is better to just change all to false. Is there a method to determine any of this for Update Queries?
Expand|Select|Wrap|Line Numbers
  1. UPDATE Table SET Table.Selected = False WHERE (((Table.Selected)=True));
  2. UPDATE Table SET Table.Selected = False;
  3.  
1st case tests all 100K records, but only changes those that are =True. The 2nd case doesn't need to test for any condition, but must change all 100K records to False.
Jul 10 '07 #1
9 3296
NeoPa
32,556 Recognized Expert Moderator MVP
You have (accidentally) posted this question in the Access Articles section. This is NOT an article.
I'm moving this to the main Access questions forum.

MODERATOR.
Jul 11 '07 #2
NeoPa
32,556 Recognized Expert Moderator MVP
This is an interesting question (well pair of them).
Unfortunately I don't know what 'efficiencies' are applied by the VBA compiler. I know that some compilers do apply such, but I've no idea if VBA does (I suspect not though).

As to your data (query) efficiency question, I can only suggest that you set up a test using a large number of records to find out what the situation is for your size of database and table. I imagine it varies with different parameters, but your test would give you a general ball-park feel for the issue anyway.
Jul 11 '07 #3
JustJim
407 Recognized Expert Contributor
You might want to check out this post in the articles section about timing of processes in Access.

Jim
Jul 12 '07 #4
OldBirdman
675 Contributor
I'm sorry for posting in the wrong section. Thanks for re-posting correctly.

Thank you for the nice tool, timeGetTime(). It seems to allow almost anything inside a test loop. So I thought I would write a general program to compare 2 (or more) variations for efficiency. So I wrote the code:
Expand|Select|Wrap|Line Numbers
  1.     iiUpperLimit = strUpperLimit 'Inputted value by User
  2.     iiMaxTime = strMaxTimeInSeconds * 1000 + iiStartTime 'Inputted value by User    iiStartTime = timeGetTime()
  3.  
  4.     For iiCounter = 1 To iiUpperLimit 'Do 1,000,000 times per User
  5.         If timeGetTime() > iiMaxTime Then
  6.             'Avoid infinite loop
  7.             TimeTest = "Loop exceeded " & strMaxTimeInSeconds & _
  8.                     " seconds.  Iterations = " & iiCounter
  9.             Exit Function
  10.         End If
  11.  
  12.         Select Case (iCase)
  13.         Case 1
  14.             wk = Sqr(iiCounter)
  15.         Case 2
  16.             wk = iiCounter * iiCounter
  17.         Case 3
  18.         Case 4
  19.         Case 5
  20.         End Select
  21.     Next iiCounter
  22.  
  23.     iiEndTime = timeGetTime()
  24.     Result = "Time (Seconds) = " & (iiEndTime - iiStartTime) / 1000 & "; Iterations = " & _
  25.             Format(iiUpperLimit, "###,###,###,###")
  26.  
I have disconnected my connection to the internet, and I (think that) I don't have anything running in background.

Then I thought I should "Calibrate" this, to determine the overhead time for the "TimeOut" test and the "Select Case". So I removed the 2 tests at Case 1 and Case 2 (Commented out). This left nothing to do no matter which case was done. The differences in time should only be the overhead in progressing further through the Select List. (Select case seems to be equivalent to If 1 then ... elseif 2 then ... elseif 3 then ... etc.).

I have run this routine many times, and have not been able to determine the overhead in the loop.
Here are the results of 6 consecutive tests, in milleseconds:
Test1: 2324 2654 6589 6870 7190
Test2: 3244 3425 6259 6850 7120
Test3: 5098 6108 6540 6850 4046
Test4: 3234 3906 5658 5989 9493
Test5: 5098 6108 6540 6850 4046
Test6: 5098 5498 7200 11256 12358
These are 6 consecutive test runs, no run was deleted to give maximum deviation results, or in any way to distort my results I would expect the first column to be the true overhead, and columns 2-5 incremental difference to be identical as VBA tests each "Case". In no case would I expect a column value to be less than the preceeding column value, as in rows 3 and 5.

So now I don't think the problem is Access, but something to do with Windows, i.e. what is running in background and that I don't know about. I am completely disconnected from the internet (wireless card is removed). I have re-booted, and Access is the only program running.

Yeah, I could have pasted code from the previous answer into a program, and not questioned the logic/method presented. That is not my way, as those who have read my previous posts know. I tested and came up short.

I will have questions as a result of my testing. How can I stop an infinite loop in the procedure that calls the above test code, or even display the progress of a loop.??.

Now let's go forward and help me understand the above table of results.

Old Birdman
Jul 13 '07 #5
NeoPa
32,556 Recognized Expert Moderator MVP
Breaking into code is usually done from the keyboard with Ctrl-Break (where Break is the Pause/Break key, normally over at the top-right of a keyboard somewhere).
There are a number of ways to display the progress of a loop, but probably the most accurate way (that effects the timing of the loop the least), would be using Debug.Print to display something to the Immediate Pane of the Debugging window. This cannot be seen while the code is executing though, and has a limited buffer for showing data.
Jul 13 '07 #6
ADezii
8,834 Recognized Expert Expert
Efficiency

I've never stumbled on any discussion of efficiency of various methods of coding, although I have found posts on various forums where individuals were concerned with efficiency. I'm not concerned when dealing with user typing, but I am if a procedure is called by a query.

Does the VBA compiler generate "in-line" code for some apparent function calls? For example, y = Abs(x) might be compiled as y = x & mask. The string functions Left, Right, and Mid might also be compiled into compact code, and not be functions at all. Seems like y = x and y = Left(x, 4) might compile to Move Addrss x, Lenth = Len(x) to Address y or Move Address x, Length = 4 to Address y. No time/efficiency difference.

Second efficiency question. I have a table with 100K records, one field is "Selected", a boolean field. To clear all selected items, I run an update query. Which is better? If one is better, where is the break point. Obviously if Selected is 99% of the table size, it is better to just change all to false. Is there a method to determine any of this for Update Queries?
Expand|Select|Wrap|Line Numbers
  1. UPDATE Table SET Table.Selected = False WHERE (((Table.Selected)=True));
  2. UPDATE Table SET Table.Selected = False;
  3.  
1st case tests all 100K records, but only changes those that are =True. The 2nd case doesn't need to test for any condition, but must change all 100K records to False.
When VBA compiles code, it stores a tokenized version of the original text and a compiled version. What exactly, this tokenized version consists of, I'm not really sure. When Access prepares to run previously compiled code, it loads just the compiled version into memory and runs that compiled code. For uncompiled code, which can result from a variety of changes to Objects and their encapsulated code, Access must load the original version into memory and then compile the code as needed.
Jul 14 '07 #7
OldBirdman
675 Contributor
I have not responded fully to the ideas presented in response to my questions. Apparently, something is running in my computers that I cannot control. I've been running spyware detection programs, virus scans, etc.

Preliminary results show that the string-handling functions mid, left, right are true functions, called each time, even if all the parameters are constants, i.e. x = Mid("ABCDE",2,4). I haven't got any further as I want to know what is running on these computers.

About queries, I created a table of 10,000 rows, each about 2K so that everything could not be done in memory. Preliminary results are that there is hidden indexing, and therefore SELECTing the records to change first is more efficient than just changing all records. If any are interested, I should be able to report on both these issues within a week.

Thanks for all who responded. I needed all of the help I got.

I will get back to this issue soon.

Old Birdman
Jul 19 '07 #8
NeoPa
32,556 Recognized Expert Moderator MVP
Thanks for your update.
I, for one, am interested in anything you find out about Access performance.
Jul 19 '07 #9
ADezii
8,834 Recognized Expert Expert
I'll second that, I too am also interested in anything that you may turn up.
Jul 19 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

7
1522
by: pmatos | last post by:
Hi all, I've been having questions about strings, references, initializations... I've created code (which will not compile due to a reference problem) and I'd like comments on why this won't...
8
3707
by: Bruce Duncan | last post by:
I have been starting to use Javascript a lot lately and I wanted to check with the "group" to get your thoughts on code efficiency. First, is there a good site/book that talks about good and bad...
92
3978
by: Dave Rudolf | last post by:
Hi all, Normally, I would trust that the ANSI libraries are written to be as efficient as possible, but I have an application in which the majority of the run time is calling the acos(...)...
10
1886
by: saraca means ashoka tree | last post by:
The following code is the heart of a program that I wrote to extract html tags from a webpage. How efficient is my code ?. Is there still possible way to optimize the code. Am I using everything as...
15
5039
by: Fady Anwar | last post by:
Hi while browsing the net i noticed that there is sites publishing some software that claim that it can decompile .net applications i didn't bleave it in fact but after trying it i was surprised...
1
2266
by: Tomás | last post by:
dynamic_cast can be used to obtain a pointer or to obtain a reference. If the pointer form fails, then you're left with a null pointer. If the reference form fails, then an exception is thrown....
239
10019
by: Eigenvector | last post by:
My question is more generic, but it involves what I consider ANSI standard C and portability. I happen to be a system admin for multiple platforms and as such a lot of the applications that my...
3
1970
by: Alpha83 | last post by:
Hi, Is there a code measuring tool that tells you which is more efficient cost-wise. For example, if I were to compare the following two identical code blocks, how do I know, which is more...
4
1695
by: bob_jenkins | last post by:
C# allows code to be generated, but the generated code is in its own assembly. Is there a way for that generated code to access internal classes in the assembly that produced it? To have the...
5
3845
by: vamsioracle | last post by:
Hi all, I have a problem with the ult_smtp package. Let me explain how the structure of my code is procedure------------ begin declarations of variables and cursors...
0
7103
Oralloy
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,...
0
7137
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...
1
6809
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...
0
7194
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...
0
3044
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...
0
3038
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1355
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
587
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
234
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...

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.