1. Jim Reese
  2. PowerBuilder
  3. Friday, 22 March 2024 16:13 PM UTC

We have a value that is stored as varchar, but it contains numeric data with a decimal to 2 places. It is an ID field, and that's just the way it has evolved over the years. For datawindow sorting, the application wraps the sort column name with double(colname) so that it will sort like a number. I recently discovered that with a result having about 8,000 rows, while other columns in the datawindow sort in less than a second, when this column is sorted on, it takes almost 2 minutes.

Changing the double() function to dec(), the sort time reduces to 18 seconds. 

This app is so old, it may have been implemented prior to dec() support, but thought I'd put this out here as a heads up, dec() appears to be significantly more efficient than double() when converting a string to a number containing a decimal.

Roland Smith Accepted Answer Pending Moderation
  1. Saturday, 23 March 2024 03:48 AM UTC
  2. PowerBuilder
  3. # 1

For PB 10.5 the Decimal datatype was changed from 18 places to 28 places.

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 22 March 2024 16:33 PM UTC
  2. PowerBuilder
  3. # 2

Thank you for letting us know about this, Jim.

Because the Double datatype is a floating-point representation of a number, it can be (and typically is) only an approximation for a decimal value, whereas the Decimal datatype is an exact representation of a decimal value.

Comment
  1. Benjamin Gaesslein
  2. Tuesday, 26 March 2024 11:22 AM UTC
I do wonder why Double() would be less performant than Dec(). Handling decimal data is usually *less* performant than floating point data because floating point math is directly supported by hardware.
  1. Helpful
  1. John Fauss
  2. Tuesday, 26 March 2024 13:35 PM UTC
Any sort operation has to perform a large number of comparisons of the values of the sort column(s) to be able to determine the relative row order. Purely speculation on my part, but I wonder if the comparison of floating-point values is much more inefficient than floating-point mathematical operations.
  1. Helpful
  1. Benjamin Gaesslein
  2. Tuesday, 26 March 2024 14:07 PM UTC
In a quick test, doing ten million comparisons between two double variables in a loop takes 4578ms on my machine, while ten million decimal comparisons take 4812ms. That's not using a dw, though.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.