473,395 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 GetArrayPosition(ByVal ipRemoteEndPoint As String, ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer)
For i As Integer = 0 To aryDevice.GetUpperBound(1)
If aryDevice(0, i) = ipRemoteEndPoint.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 1496
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*@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.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 GetArrayPosition(ByVal ipRemoteEndPoint As String, ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer) For i As Integer = 0 To aryDevice.GetUpperBound(1)
If aryDevice(0, i) = ipRemoteEndPoint.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.Subtract(startTime)
Gerald

"Dan" <Da*@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.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

"Cablewizard" 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*@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.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 GetArrayPosition(ByVal ipRemoteEndPoint As
String, ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer)
For i As Integer = 0 To aryDevice.GetUpperBound(1)
If aryDevice(0, i) = ipRemoteEndPoint.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
"Cablewizard" 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*@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.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 GetArrayPosition(ByVal ipRemoteEndPoint As String,

ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer)
For i As Integer = 0 To aryDevice.GetUpperBound(1)
If aryDevice(0, i) = ipRemoteEndPoint.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****@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.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
"Cablewizard" 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*@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.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 GetArrayPosition(ByVal ipRemoteEndPoint As
String, ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer)
For i As Integer = 0 To aryDevice.GetUpperBound(1)
If aryDevice(0, i) = ipRemoteEndPoint.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
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...
2
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...
8
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...
193
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...
6
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
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. ...
0
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...
6
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:...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...
0
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
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
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,...

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.