ImportC ""
atof.d(*txt) As "_atof"
EndImport
; Macro ValD ;-> uncomment to use new procedure instead of built-in
; _ValD
; EndMacro
Procedure.d _ValD(str.s)
Protected *mem=Ascii(str)
dret.d=atof(*mem)
FreeMemory(*mem)
ProcedureReturn dret
EndProcedure
Define ret.d, i, u
Dim t$(10)
For i=0 To 10
t$(i)=Str(Random(32767,0))+"."+Random(32767,0)
Next
iStart=ElapsedMilliseconds()
For u=0 To 100000
For i=0 To 10
ret=ValD(t$(i))
Next i
Next u
Debug "Duration:"+Str(ElapsedMilliseconds()-iStart)
iStart=ElapsedMilliseconds()
For u=0 To 100000
For i=0 To 10
ret=_ValD(t$(i))
Next i
Next u
Debug "Duration:"+Str(ElapsedMilliseconds()-iStart)
atof() doesn't work for me Oliver, I think it could be a 64 bit compatibility issue.
wtof() works though, and as this doesn't require the ascii conversion it's an order of magnitude faster. A downside for me was that it didn't handle conversion of PBs Binary (%) or Hexadecimal ($) prefixed strings.
Three things:
1. You don't measure time in Debug mode.
2. An additional function call and string conversion adds a lot of time.
3. _atof does not exist on Linux it seems. But atof does. A version for UCS-2 strings like Purebasic uses them internally seems not to be available.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
EnableExplicit
ImportC ""
atof.d(*txt) As "atof"
EndImport
; Macro ValD ;-> uncomment to use new procedure instead of built-in
; _ValD
; EndMacro
Procedure.d _ValD(str.s)
Protected *mem = Ascii(str)
Protected dret.d = atof(*mem)
FreeMemory(*mem)
ProcedureReturn dret
EndProcedure
OpenConsole()
Define ret.d, i, u, timeDiff
Dim t$(10)
For i = 0 To 10
t$(i) = Str(Random(32767,0)) + "." + Random(32767,0)
Next
timeDiff = ElapsedMilliseconds()
For u = 0 To 100000
For i = 0 To 10
ret = ValD(t$(i))
Next
Next
timeDiff = ElapsedMilliseconds() - timeDiff
PrintN(" ValD: " + timeDiff + " ms")
timeDiff = ElapsedMilliseconds()
For u = 0 To 100000
For i = 0 To 10
ret = _ValD(t$(i))
Next
Next
timeDiff = ElapsedMilliseconds() - timeDiff
PrintN("_ValD: " + timeDiff + " ms")
Input()
CloseConsole()
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.