Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

floating point calculations as a bottle neck?  RSS feed

 
Elhanan Maayan
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we have this little method the runs on a nested loop (outer loop runs on around 8000 cells array, inner loop runs on 12 cells)

the entire thing runs on a sperate thread that iterates on a loop (it cannot run on multiple threads.
we've discovered that using the float values _weightedMap actually slows the down process, (values in the queue the thread is working on build up) even jprofilder won't show this specific method as the bottle neck but only the methods which run the outer loop.

could this be possible (this is java 7)

 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you asking if it's possible that floating point calculations are the bottleneck in your program? Sure, I suppose it's possible. Hard to tell really, but it's always possible for something to be a bottleneck if it's repeated enough times in a tight loop. However, looking at your method, I might first consider that the biggest performance hit comes from the use of a Map, _weightedMap. Considering both the key and value are primitives, this results in a lot of boxing and unboxing, in addition to the hashing and lookup. And considering you assume that all possible key values will have a weight entry (else there would be a NullPointerException) - could you perhaps just use a float[] array instead? Where the key becomes the index of the array? (You might have to add an offset to ensure the index is positive.) I suspect this would eliminate your biggest current bottleneck. Might be worth a try, at least.
 
Elhanan Maayan
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:Are you asking if it's possible that floating point calculations are the bottleneck in your program? Sure, I suppose it's possible. Hard to tell really, but it's always possible for something to be a bottleneck if it's repeated enough times in a tight loop. However, looking at your method, I might first consider that the biggest performance hit comes from the use of a Map, _weightedMap. Considering both the key and value are primitives, this results in a lot of boxing and unboxing, in addition to the hashing and lookup. And considering you assume that all possible key values will have a weight entry (else there would be a NullPointerException) - could you perhaps just use a float[] array instead? Where the key becomes the index of the array? (You might have to add an offset to ensure the index is positive.) I suspect this would eliminate your biggest current bottleneck. Might be worth a try, at least.


actually i considered that as well, but using an array didn't work, i don't recall if i used Float[] or float[] , but having the array, didn't do much. the table itself was only 70 values, i had to negate the keys as they were negative, so i doubled them by -1, before extraction by index.
but as i said, that didn't help.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What is the range of values for "rounded"? A reasonable number for the size of a float[]?

Bill
 
Elhanan Maayan
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
between 30-100
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elhanan Maayan wrote:between 30-100

So an obvious optimization would be to replace that Map lookup with a float[] - saving all sorts of object creation and memory.

If I wanted to evaluate the actual floating point time, an obvious test would be to comment out the


just return a constant and see what happens to your run times.

Bill
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!