Re: Faster ways to convert strings to doubles?
Posted: Tue Sep 06, 2016 6:46 pm
@wilbert
Thanks for the tip on the pointer. That alone shaved off another 100 milliseconds.
As for removing the division it doesn't seem to give a very noticeable speed boost. For a quick test I swapped out "/ Factor" to "* 0.00000000001" which is the value to use when Factor = 100000000000, but that only shaved of 10 milliseconds. If I add a counter and then look up the corresponding value I'd imagine I'd lose a couple of those milliseconds.
It may be minor, but a speed boost is a speed boost.
Procedure with the new string pointer and a commented out multiplication test.
Thanks for the tip on the pointer. That alone shaved off another 100 milliseconds.
As for removing the division it doesn't seem to give a very noticeable speed boost. For a quick test I swapped out "/ Factor" to "* 0.00000000001" which is the value to use when Factor = 100000000000, but that only shaved of 10 milliseconds. If I add a counter and then look up the corresponding value I'd imagine I'd lose a couple of those milliseconds.
It may be minor, but a speed boost is a speed boost.

Procedure with the new string pointer and a commented out multiplication test.
Code: Select all
Procedure.d MATH_UnicodeValD(*StringToConvert.String)
Protected MainValue.q, DezimalValue.q, Factor.q, ValueSign.q, *pString.Character
*pString = *StringToConvert
ValueSign = 1
Factor = 1
If *pString\c = '-'
*pString + 2
ValueSign = -1
EndIf
While *pString\c
If *pString\c = '.'
*pString + 2
Break
Else
MainValue * 10 + (*pString\c - '0')
EndIf
*pString + 2
Wend
While *pString\c
DezimalValue * 10 + (*pString\c - '0')
Factor * 10
*pString + 2
Wend
;## For comparing division to multiplication.
;## When String = "-13215.33414554664" then Factor = 100000000000.
;ProcedureReturn (MainValue + (DezimalValue * 0.00000000001)) * ValueSign
ProcedureReturn (MainValue + (DezimalValue / Factor)) * ValueSign
EndProcedure