Performance Problem using DLL

VBasic

Member
Joined
Feb 21, 2008
Messages
5
Programming Experience
10+
I’ve developed a VB.Net class library project (DLL) to perform a binary search function. It works in a slightly different way from the Array.BinarySearch function provided by VB.Net, but for this process, either search can be used, as I will explain.

Inside the DLL there is a single Class.vb module. Here is the thing I’ve found that I cannot explain. I created a test project in order to test the DLL. When I used the DLL in my test project (by adding a reference to the DLL), and instantiated the class module, I found that using the class in this way caused the performance to be atrocious. Alternatively, I added a copy of the DLL’s Class.vb module directly into my test project, removed the reference to the DLL and the performance was much better.

For example, in my test material, I have an array of 79,000 + items (they’re actually zip codes, 5 bytes each). I load up the array then loop through the array one at a time to use as a compare argument in the binary search. So each item is actually in the array. To prove the process, I altered some of the zip code arguments before calling the search to insure that a percentage of the total would come back “not found”.

Using the Array.BinarySearch function provided by VB.Net, I consistently perform a search on all 79,000+ items in 2 seconds. That’s PDF for an old IBM Windows 2000 laptop, vintage 2001, on its last legs.

Using the local Class.vb module, (copied into the test project), I can perform the exact same process in 3 –4 seconds.

Using the instantiated Class.vb module from the DLL runs forever. It runs so long that I’ve never actually waited until it completes so I don’t know how long it would run. Single stepping through the code reveals that calling the routine (in the DLL) to a human is relatively fast. However, the clock doesn’t lie. It takes a lot longer to loop through 79,000+ items to perform this process using the DLL than either of the other two methods.

No, I am not reinstantiating the object for each call in the loop.
No, I am never leaving the routine (except to call the binary search method) during the entire process.

So, the questions are:
Am I doing something wrong when I use the DLL?
Must I add the reference to the DLL in my test project in a special way?
Has anyone else ever had this problem or is this a common accepted condition when using DLLs?

I’ve run all the above in both debug mode as well as EXE and the results are nearly the same. The EXE as expected is a bit faster.
 
Found the Solution:
I didn't know a DLL project has more than one DLL output file in the project. I changed my test program to reference the DLL contained within the Release folder and now I obtain the same processing speed using the DLL.

vbasic
 
Back
Top