| When doing arithmetic in PowerBuilder it is easy not to give any
consideration to the Datatypes you are performing arithmetic upon. I recently found out
that although PowerBuilder allows you to perform arithmetic using all numeric Datatypes
the internal engine will always use the largest internal Datatype for the calculation to
reduce the risk of rounding and overflow. You may be wondering where this is leading
but take for example the integer Datatype. PowerBuilder always converts this
to a long before performing any math. This is useful in stopping overflow and
rounding errors but means that whenever an integer is used it is always cast to a long
before use.
Consider the following Code:
Integer li_I, li_J, li_K
li_I = 4
li_J = 80
li_K = li_I + li_J
li_K ++
The line li_K = li_I + li_J would execute as follows: cast li_I to long,
cast li_J to long, perform addition, cast resulting long to integer, assign to li_K.
The line li_K ++ would execute as follows: cast li_K to long, add one,
cast resulting long to integer, assign to li_K.
You can see that in each of these steps there is a lot of casting taking place. You may
well argue that its the 90's machines are getting faster and a cast takes only a
nanosecond to execute. But in timed tests even simple integer match like the above code
when changed to use the long Datatype will run 20% faster than its
integer counter part.
I will let you draw your own conclusion! |