After parsing text I get numbers formatted like:
$2,279.59
and
(212) 718-1288
Which need to be turned into a LONG and QUAD respectivly.
From PB help:
>VAL stops analyzing string_expression when non-numeric characters are encountered...
Oh darn.
So I have been using:
sNumRem = "+?/\()$*%, " ' Stuff to remove from numbers
MyLong = VAL( REMOVE$( sNum, ANY sNumRem ) )
This works but is not clock cycle friendly but does resolve
floating point numbers by rounding them.
checking poffs I do not find any Nifty ASM contribution from the
usual suspects so here is my contribution:
I would like to find a fast method in PB first, and THEN convert it ASM perhaps.
Comments?
[This message has been edited by Mike Trader (edited July 26, 2007).]
$2,279.59
and
(212) 718-1288
Which need to be turned into a LONG and QUAD respectivly.
From PB help:
>VAL stops analyzing string_expression when non-numeric characters are encountered...
Oh darn.
So I have been using:
sNumRem = "+?/\()$*%, " ' Stuff to remove from numbers
MyLong = VAL( REMOVE$( sNum, ANY sNumRem ) )
This works but is not clock cycle friendly but does resolve
floating point numbers by rounding them.
checking poffs I do not find any Nifty ASM contribution from the
usual suspects so here is my contribution:
Code:
#COMPILE EXE "Val2.exe" ' #DIM ALL '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤' SUB time_stamp_count(tick AS QUAD) ' CPU Clock count Charles E V Pegge '---------------------------' ' ' approx because it is not a serialised instruction ' ' it may execute before or after other instructions ' ' in the pipeline. ! mov ebx,tick ' var address where count is to be stored. ! db &h0f,&h31 ' RDTSC read time-stamp counter into edx:eax hi lo. ! mov [ebx],eax ' save low order 4 bytes. ! mov [ebx+4],edx ' save high order 4 bytes. '---------------------------' END SUB '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤' FUNCTION Val2( sNum AS STRING ) AS LONG ' Approx 2500 clock cycles LOCAL i, j, StrLen, NegFlag, Power, RetVal AS LONG LOCAL a, b AS BYTE PTR LOCAL sBuff AS STRING StrLen = LEN(sNum) sBuff = SPACE$(StrLen) ' make an empty buffer a = STRPTR(sNum) b = STRPTR(sBuff) j = 0 FOR i = 0 TO StrLen-1 SELECT CASE @a[i] CASE 48 TO 57 ' 0 thru 9 @b[j] = @a[i] ' xfer the number to the buffer INCR j CASE 46 ' Decimal point EXIT FOR ' truncate floating point number (need a better solution) CASE 45 ' Minus sign NegFlag = 1 ' change LSB of long? CASE ELSE END SELECT NEXT i ' MSGBOX STR$(j),64,sBuff FOR i = 0 TO j-1 Power = j-i-1 RetVal = RetVal + (@b[i]-48)*10^Power NEXT FUNCTION = RetVal END FUNCTION '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤' FUNCTION PBMAIN( ) LOCAL cBeg, cEnd AS QUAD ' for time stamp, measuring cpu clock cycles LOCAL i, RetVal, nLoops AS LONG LOCAL sNumRem AS STRING sNumRem = "+?/\()$*%, " ' Stuff to remove from numbers time_stamp_count(cBeg) ' measuring cpu clock cycles. The overhead just for making this call is about 25 clocks nLoops = 1000 FOR i = 1 TO nLoops RetVal = VAL( REMOVE$( "$2,279.59", ANY sNumRem ) ) ' 5600 clock cycles NEXT time_stamp_count(cEnd) ' measuring cpu clock cycles. The overhead just for making this call is about 25 clocks MSGBOX "Total Processor Cycles="+STR$( (cEnd-cBeg)\nLoops ),64,"VAL =" + STR$(RetVal) '======================= time_stamp_count(cBeg) ' measuring cpu clock cycles. The overhead just for making this call is about 25 clocks nLoops = 1000 FOR i = 1 TO nLoops RetVal = Val2("$2,279.59") ' Approx 2500 clock cycles NEXT time_stamp_count(cEnd) ' measuring cpu clock cycles. The overhead just for making this call is about 25 clocks MSGBOX "Total Processor Cycles="+STR$( (cEnd-cBeg)\nLoops ),64,"VAL2 =" + STR$(RetVal) END FUNCTION '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤'
I would like to find a fast method in PB first, and THEN convert it ASM perhaps.
Comments?
[This message has been edited by Mike Trader (edited July 26, 2007).]
Comment