T
ThunderMusic
Hi,
I need to optimize a close loop. Usually I would use assembly, but I don't
event know if it's available to VB.NET. I'll explain the case and maybe some
of you will be able to advise me.
I have a byte() (byte array) containing about 100,000 elements (a bit less,
but always is around 80,000-95,000). I need to take the data from it as
int16 and compare the int16 to a reference value
for now, I'm using a MemoryStream created from the byte(), a BinaryReader
that reads from the MemoryStream (ReadInt16) and then compare the int16 to a
reference value and return false if the int16 is greater than the reference
value. if all the values are lower than the reference value, then the
function returns true. If it returns after the first loop or so, it's ok,
but if it runs through all the elements it's way too long. In assembly it
would take way less time than that, because I could move the reference value
in one of the CPU's register and leave it there as long as my loop runs and
iterate directly in the byte() to get 2 bytes at a time.
In VB.NET it's a function that stands in about 10 lines of code (maybe even
lower), but it takes up to 50% of the CPU (when looked in the task manager)
which is way too much because it runs very often. When it does not run (many
other things are running in the app), the app takes about 1%-2% of the CPU,
when this close loop starts being called, the app get's to 30%-50% of the
CPU... it's a bit excessive due to the fact that the function is called
about 8-10 times a second.
thanks for your help
ThunderMusic
I need to optimize a close loop. Usually I would use assembly, but I don't
event know if it's available to VB.NET. I'll explain the case and maybe some
of you will be able to advise me.
I have a byte() (byte array) containing about 100,000 elements (a bit less,
but always is around 80,000-95,000). I need to take the data from it as
int16 and compare the int16 to a reference value
for now, I'm using a MemoryStream created from the byte(), a BinaryReader
that reads from the MemoryStream (ReadInt16) and then compare the int16 to a
reference value and return false if the int16 is greater than the reference
value. if all the values are lower than the reference value, then the
function returns true. If it returns after the first loop or so, it's ok,
but if it runs through all the elements it's way too long. In assembly it
would take way less time than that, because I could move the reference value
in one of the CPU's register and leave it there as long as my loop runs and
iterate directly in the byte() to get 2 bytes at a time.
In VB.NET it's a function that stands in about 10 lines of code (maybe even
lower), but it takes up to 50% of the CPU (when looked in the task manager)
which is way too much because it runs very often. When it does not run (many
other things are running in the app), the app takes about 1%-2% of the CPU,
when this close loop starts being called, the app get's to 30%-50% of the
CPU... it's a bit excessive due to the fact that the function is called
about 8-10 times a second.
thanks for your help
ThunderMusic