473,662 Members | 2,622 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Suggestions to increase the performance of searching my array?

Dan
I wonder if anyone has suggestions for reducing the amount of time it would take to search my array using the function that I have written. I want to find a position in the array of an item that matches on all three variables. Suggestions?

Public Shared Function GetArrayPositio n(ByVal ipRemoteEndPoin t As String, ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer)
For i As Integer = 0 To aryDevice.GetUp perBound(1)
If aryDevice(0, i) = ipRemoteEndPoin t.ToString And aryDevice(1, i) = intEngine_Type And aryDevice(2, i) = intEngine_ID Then
Return i
End If
Next
Return -1
End Function
Nov 20 '05 #1
5 1512
How can you create an array include different datatype (String, Integer).
I suggest you use datatable.
Nov 20 '05 #2
Dan,

First, you don't want to mix types in an array. I noticed you have String and
Integer types.
If all 3 dimensions of your array reference a single item, then I might use an
array of a Structure with a fixed length string.

Second, do not perform multiple tests in a single line using the "And" operator.
VB must resolve all the expressions prior to evaluating your comparison test.
In cases where the first test fails, it will still perform the other two tests
along with all the unnecessary overhead.
VB.Net does include the "AndAlso" and "OrElse" operators which will provide a
"Short-Circuit" method of evaluation.
Meaning the first test to fail will cause the whole expression to fail, and
return False without evaluating the subsequent expressions.
IMHO, I prefer to break them into separate tests for readability.
In addition, it also allows you to perform other operations between tests, as in
the case of indexing.

Third, along with the second, perform your tests in the order which will most
likely give you a False first.
This will allow you to minimize the number of unnecessary comparisons.
Sometimes that fastest way to get to your desired item is to eliminate as many
of the items as quickly as possible that cannot fulfill your criteria.

Fourth, if you have a large number of elements in the array and you will be
accessing them a lot, then I recommend pre-sorting the array on an appropriate
key. You could also create Index arrays with pointers into the primary array and
use this to minimize the number of elements to test.
The best implementation of an Index, if even appropriate, would be dependant
upon the contents of the array and intended usage.

Hope this helps,
Gerald
"Dan" <Da*@discussion s.microsoft.com > wrote in message
news:65******** *************** ***********@mic rosoft.com...
I wonder if anyone has suggestions for reducing the amount of time it would take to search my array using the function that I have written. I want to find
a position in the array of an item that matches on all three variables.
Suggestions?
Public Shared Function GetArrayPositio n(ByVal ipRemoteEndPoin t As String, ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer) For i As Integer = 0 To aryDevice.GetUp perBound(1)
If aryDevice(0, i) = ipRemoteEndPoin t.ToString And aryDevice(1, i) = intEngine_Type And aryDevice(2, i) = intEngine_ID Then Return i
End If
Next
Return -1
End Function

Nov 20 '05 #3
You can use timers and timespans and set up test cases.
Get your start time, then process a whole bunch of them, then get end time and
determine the elapsed time.
Do the same for other solutions.
Run them a bunch of times looking for consistency, since a whole mess of things
beyond your control could affect the outcome of a single test.
Make sure your test case will give you a good mix criteria, as one method might
be able to find a particular value much faster than another, but might be much
slower at finding a different value.

Rough sample would be:

Dim startTime, endTime As Date
Dim elapsed As TimeSpan
startTime = Now

'Do your work here

endTime = Now
elapsed = endTime.Subtrac t(startTime)
Gerald

"Dan" <Da*@discussion s.microsoft.com > wrote in message
news:3A******** *************** ***********@mic rosoft.com...
Those are excellent ideas and I will give them a try. I find myself now wondering how I can tell whether one solution is faster than the other?
Recognizing that we are talking about miliseconds here, but is there a built in
way in VB.Net to time the execution of a portion of code?
Thanks,
Dan

"Cablewizar d" wrote:
Dan,

First, you don't want to mix types in an array. I noticed you have String and Integer types.
If all 3 dimensions of your array reference a single item, then I might use an array of a Structure with a fixed length string.

Second, do not perform multiple tests in a single line using the "And" operator. VB must resolve all the expressions prior to evaluating your comparison test. In cases where the first test fails, it will still perform the other two tests along with all the unnecessary overhead.
VB.Net does include the "AndAlso" and "OrElse" operators which will provide a "Short-Circuit" method of evaluation.
Meaning the first test to fail will cause the whole expression to fail, and
return False without evaluating the subsequent expressions.
IMHO, I prefer to break them into separate tests for readability.
In addition, it also allows you to perform other operations between tests, as in the case of indexing.

Third, along with the second, perform your tests in the order which will most likely give you a False first.
This will allow you to minimize the number of unnecessary comparisons.
Sometimes that fastest way to get to your desired item is to eliminate as many of the items as quickly as possible that cannot fulfill your criteria.

Fourth, if you have a large number of elements in the array and you will be
accessing them a lot, then I recommend pre-sorting the array on an appropriate key. You could also create Index arrays with pointers into the primary array and use this to minimize the number of elements to test.
The best implementation of an Index, if even appropriate, would be dependant
upon the contents of the array and intended usage.

Hope this helps,
Gerald
"Dan" <Da*@discussion s.microsoft.com > wrote in message
news:65******** *************** ***********@mic rosoft.com...
I wonder if anyone has suggestions for reducing the amount of time it
would take to search my array using the function that I have written. I want to find a position in the array of an item that matches on all three variables.
Suggestions?

Public Shared Function GetArrayPositio n(ByVal ipRemoteEndPoin t As
String, ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer)
For i As Integer = 0 To aryDevice.GetUp perBound(1)
If aryDevice(0, i) = ipRemoteEndPoin t.ToString And
aryDevice(1, i) = intEngine_Type And aryDevice(2, i) = intEngine_ID Then
Return i
End If
Next
Return -1
End Function


Nov 20 '05 #4
I thought that in VB.Net the if statements had changed such that if the first expression was false, then the following expressions after and were not evaluated..is this not the case?
--
Dennis in Houston
"Cablewizar d" wrote:
Dan,

First, you don't want to mix types in an array. I noticed you have String and
Integer types.
If all 3 dimensions of your array reference a single item, then I might use an
array of a Structure with a fixed length string.

Second, do not perform multiple tests in a single line using the "And" operator.
VB must resolve all the expressions prior to evaluating your comparison test.
In cases where the first test fails, it will still perform the other two tests
along with all the unnecessary overhead.
VB.Net does include the "AndAlso" and "OrElse" operators which will provide a
"Short-Circuit" method of evaluation.
Meaning the first test to fail will cause the whole expression to fail, and
return False without evaluating the subsequent expressions.
IMHO, I prefer to break them into separate tests for readability.
In addition, it also allows you to perform other operations between tests, as in
the case of indexing.

Third, along with the second, perform your tests in the order which will most
likely give you a False first.
This will allow you to minimize the number of unnecessary comparisons.
Sometimes that fastest way to get to your desired item is to eliminate as many
of the items as quickly as possible that cannot fulfill your criteria.

Fourth, if you have a large number of elements in the array and you will be
accessing them a lot, then I recommend pre-sorting the array on an appropriate
key. You could also create Index arrays with pointers into the primary array and
use this to minimize the number of elements to test.
The best implementation of an Index, if even appropriate, would be dependant
upon the contents of the array and intended usage.

Hope this helps,
Gerald
"Dan" <Da*@discussion s.microsoft.com > wrote in message
news:65******** *************** ***********@mic rosoft.com...
I wonder if anyone has suggestions for reducing the amount of time it would

take to search my array using the function that I have written. I want to find
a position in the array of an item that matches on all three variables.
Suggestions?

Public Shared Function GetArrayPositio n(ByVal ipRemoteEndPoin t As String,

ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer)
For i As Integer = 0 To aryDevice.GetUp perBound(1)
If aryDevice(0, i) = ipRemoteEndPoin t.ToString And aryDevice(1, i)

= intEngine_Type And aryDevice(2, i) = intEngine_ID Then
Return i
End If
Next
Return -1
End Function


Nov 20 '05 #5
Yes, this is not the case. :-)
IF, AND, OR are bitwise operators that also conveniently serve as logical
boolean operators.
In the early days, MS had planned on implementing, and they actually made it
into Beta, seperate operators for bitwise comparison; such as BitAnd, BitOr,
etc.
However, that broke old programs and confused the VB6 converts.
So they removed them and went back to the old method.

However, they did add the AndAlso and OrElse short-circuitable logical operators
to help to deal with the inefficiency of using the bitwise operators for logical
operations. Personally, I like them seperate and was looking forward to the
seperation, but history prevailed.

Gerald

"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:1F******** *************** ***********@mic rosoft.com...
I thought that in VB.Net the if statements had changed such that if the first expression was false, then the following expressions after and were not
evaluated..is this not the case? --
Dennis in Houston
"Cablewizar d" wrote:
Dan,

First, you don't want to mix types in an array. I noticed you have String and Integer types.
If all 3 dimensions of your array reference a single item, then I might use an array of a Structure with a fixed length string.

Second, do not perform multiple tests in a single line using the "And" operator. VB must resolve all the expressions prior to evaluating your comparison test. In cases where the first test fails, it will still perform the other two tests along with all the unnecessary overhead.
VB.Net does include the "AndAlso" and "OrElse" operators which will provide a "Short-Circuit" method of evaluation.
Meaning the first test to fail will cause the whole expression to fail, and
return False without evaluating the subsequent expressions.
IMHO, I prefer to break them into separate tests for readability.
In addition, it also allows you to perform other operations between tests, as in the case of indexing.

Third, along with the second, perform your tests in the order which will most likely give you a False first.
This will allow you to minimize the number of unnecessary comparisons.
Sometimes that fastest way to get to your desired item is to eliminate as many of the items as quickly as possible that cannot fulfill your criteria.

Fourth, if you have a large number of elements in the array and you will be
accessing them a lot, then I recommend pre-sorting the array on an appropriate key. You could also create Index arrays with pointers into the primary array and use this to minimize the number of elements to test.
The best implementation of an Index, if even appropriate, would be dependant
upon the contents of the array and intended usage.

Hope this helps,
Gerald
"Dan" <Da*@discussion s.microsoft.com > wrote in message
news:65******** *************** ***********@mic rosoft.com...
I wonder if anyone has suggestions for reducing the amount of time it
would take to search my array using the function that I have written. I want to find a position in the array of an item that matches on all three variables.
Suggestions?

Public Shared Function GetArrayPositio n(ByVal ipRemoteEndPoin t As
String, ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer)
For i As Integer = 0 To aryDevice.GetUp perBound(1)
If aryDevice(0, i) = ipRemoteEndPoin t.ToString And
aryDevice(1, i) = intEngine_Type And aryDevice(2, i) = intEngine_ID Then
Return i
End If
Next
Return -1
End Function


Nov 20 '05 #6

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

Similar topics

0
1286
by: Matt W | last post by:
Hi all, I'm planning to use MySQL's full-text search for my forum system (possibly 5+ million posts). I've been playing with it a lot lately to see the performance and functionality and have some suggestions/questions. First, since a few of you may be wanting to know, here is a thread where I was doing some speed/optimization tests and stuff with 3 million posts: http://www.sitepointforums.com/showthread.php?threadid=69555
2
2720
by: Torfi Sackbatten | last post by:
Hi Everyone, I´m asked to "speed up" a keyword search based on MySQL. The material i´m given to work with is a quite large MySQL table with 1.5 mio rows, defined something like: CREATE TABLE datarecords ( id BIGINT(20) NOT NULL auto_increment, , keywords TEXT NOT NULL,
8
2894
by: Darsant | last post by:
I'm currently reading 1-n number of binary files, each with 3 different arrays of floats containing about 10,000 values a piece for a total of about 30,000 values per file. I'm looking for a way to load them all into memory. I've tried using vector pushback with reserving, but it was horribly slow. The current method I am using is upon opening the file and reading the number of values, resizing the vectors (I have 3, one for each data...
193
9521
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I speak only of features in the spirit of C; something like object-orientation, though a nice feature, does not belong in C. Something like being able to #define a #define would be very handy, though, e.g: #define DECLARE_FOO(bar) #define...
6
12130
by: reb | last post by:
Hi, How do i increase the size of the array without losing the data of that array in c#? thanks
4
2054
by: Morten Snedker | last post by:
Scenario: From a given folder all files from all subdirs are read. These are dropped in a one-dimensional array - myArray. Once everything is in my array it is sorted and dropped in a listbox. In a textbox I can enter a search criteria. Each time I press a key the listbox is cleared and I run this code (at this point the listbox is cleared), which fills to another array - subArray:
0
1265
by: rxding | last post by:
Can Java Store Procedure increase performance Hello, Performance reason we need to move some of our code into database. Java Store Procedure is given the first choice. However, while investigating some sample code of Java store procedure, PreparedStatement seems to be a must, such as PreparedStatement pstmt = conn.prepareStatement(sql); ..., pstmt.close() in the end. My question is that if the prepareStatement(sql) is called each...
6
1394
by: Christian Sonne | last post by:
Long story short, I'm trying to find all ISBN-10 numbers in a multiline string (approximately 10 pages of a normal book), and as far as I can tell, the *correct* thing to match would be this: ".*\D*(\d{10}|\d{9}X)\D*.*" (it should be noted that I've removed all '-'s in the string, because they have a tendency to be mixed into ISBN's) however, on my 3200+ amd64, running the following:
1
1315
by: megotronx | last post by:
hello.i`m newbie in php and i need to boost performance of searching in database.I don`t know is it the mssql problem or php script for accsesing database.So i`m looking for help here.Here is the code that i suspect it is bad and slowing the performance and rising the time to select database rows. function db_get_pac_where($W_id,$surname,$name,$group,$code,$gim_data) { $connection=db_connect(); $q=" select * from COMMIS where (1=1) ";...
0
8432
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
8344
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8764
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
8546
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
8633
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
5654
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();...
0
4180
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
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.