On my machine - I did 4 cases of dividing 40 by 2 and the slowest was "x =
BITRSHIFT(40,2)"
Based on 1,000,000 iterations for each I get the following timings ...
x = 40 / 4 .. 0.1070546391
STORE 40 / 4 TO x .. 0.0636483880
x = BITRSHIFT(40,2) .. 0.1302353828
STORE BITRSHIFT(40,2) TO x .. 0.0844159499
I don't think the difference is too dramatic.
If I change the 40 to 51.2 the figures are slightly higher but in same
proportions to each other | x = BITRSHIFT(51.2,2) is still the slowest (and
of course inaccurate)
Changing to 2E9 I get pretty much the same timings as the first set.
Code I used .....
ACTIVATE SCREEN
CLEAR
SET DECIMALS TO 8
DECLARE INTEGER QueryPerformanceCounter IN C:\Windows\SysWow64\kernel32.dll;
STRING @lpPerformanceCount
DECLARE INTEGER QueryPerformanceFrequency IN
C:\Windows\SysWow64\kernel32.dll;
STRING @lpFrequency
*- Get Timer Resolution / Frequency
lcBuffer = REPLICATE(CHR(0), 8)
QueryPerformanceFrequency(@lcBuffer)
lnFrequency = buf2dword(SUBSTR(m.lcBuffer, 1, 4)) +
buf2dword(SUBSTR(m.lcBuffer, 5, 4)) * 4294967296
*----------------------------------------------------
*- Case 1 | x = 2E9 / 4
*----------------------------------------------------
STORE REPLICATE(CHR(0), 8) TO lcBuffer1, lcBuffer2
QueryPerformanceCounter(@lcBuffer1)
FOR n = 1 TO 1000000
x = 2E9 / 4
ENDFOR
QueryPerformanceCounter(@lcBuffer2)
lnStart = (buf2dword(SUBSTR(m.lcBuffer1, 1, 4)) +
buf2dword(SUBSTR(m.lcBuffer1, 5, 4)) * 4294967296) / m.lnFrequency
lnEnd = (buf2dword(SUBSTR(m.lcBuffer2, 1, 4)) +
buf2dword(SUBSTR(m.lcBuffer2, 5, 4)) * 4294967296) / m.lnFrequency
?x, lnEnd - lnStart
*----------------------------------------------------
*- Case 2 | STORE 2E9 / 4 TO x
*----------------------------------------------------
STORE REPLICATE(CHR(0), 8) TO lcBuffer1, lcBuffer2
QueryPerformanceCounter(@lcBuffer1)
FOR n = 1 TO 1000000
STORE 2E9 / 4 TO x
ENDFOR
QueryPerformanceCounter(@lcBuffer2)
lnStart = (buf2dword(SUBSTR(m.lcBuffer1, 1, 4)) +
buf2dword(SUBSTR(m.lcBuffer1, 5, 4)) * 4294967296) / m.lnFrequency
lnEnd = (buf2dword(SUBSTR(m.lcBuffer2, 1, 4)) +
buf2dword(SUBSTR(m.lcBuffer2, 5, 4)) * 4294967296) / m.lnFrequency
?x, lnEnd - lnStart
*----------------------------------------------------
*- Case 3 | x = BITRSHIFT(2E9,2)
*----------------------------------------------------
STORE REPLICATE(CHR(0), 8) TO lcBuffer1, lcBuffer2
QueryPerformanceCounter(@lcBuffer1)
FOR n = 1 TO 1000000
x = BITRSHIFT(2E9,2)
ENDFOR
QueryPerformanceCounter(@lcBuffer2)
lnStart = (buf2dword(SUBSTR(m.lcBuffer1, 1, 4)) +
buf2dword(SUBSTR(m.lcBuffer1, 5, 4)) * 4294967296) / m.lnFrequency
lnEnd = (buf2dword(SUBSTR(m.lcBuffer2, 1, 4)) +
buf2dword(SUBSTR(m.lcBuffer2, 5, 4)) * 4294967296) / m.lnFrequency
?x, lnEnd - lnStart
*----------------------------------------------------
*- Case 4 | STORE BITRSHIFT(2E9,2) TO x
*----------------------------------------------------
STORE REPLICATE(CHR(0), 8) TO lcBuffer1, lcBuffer2
QueryPerformanceCounter(@lcBuffer1)
FOR n = 1 TO 1000000
STORE BITRSHIFT(2E9,2) TO x
ENDFOR
QueryPerformanceCounter(@lcBuffer2)
lnStart = (buf2dword(SUBSTR(m.lcBuffer1, 1, 4)) +
buf2dword(SUBSTR(m.lcBuffer1, 5, 4)) * 4294967296) / m.lnFrequency
lnEnd = (buf2dword(SUBSTR(m.lcBuffer2, 1, 4)) +
buf2dword(SUBSTR(m.lcBuffer2, 5, 4)) * 4294967296) / m.lnFrequency
?x, lnEnd - lnStart
_cliptext = transform(lnEnd - lnstart)
FUNCTION buf2dword (vcBuffer)
RETURN ASC(SUBSTR(m.vcBuffer, 1,1)) + ;
BITLSHIFT(ASC(SUBSTR(m.vcBuffer, 2,1)), 8) +;
BITLSHIFT(ASC(SUBSTR(m.vcBuffer, 3,1)), 16) +;
BITLSHIFT(ASC(SUBSTR(m.vcBuffer, 4,1)), 24)
ENDFUNC
-----Original Message-----
From: ProfoxTech [mailto:[email protected]] On Behalf Of Laurie
Alvey
Sent: Thursday, 30 July 2015 7:58 PM
To: [email protected]
Subject: Re: BITRSHIFT(n,1) v n/2
Interesting. If I issue ? CAST(8E9 As I) it displays a negative 9 digit
number (-589934592). Also, I thought the limit for 32 bit integers was about
2E9.
Laurie
On 29 July 2015 at 13:42, Jean MAURICE <[email protected]> wrote:
> Hi Laurie,
> I do think that BITRSHIFT is a lot quicker than /2. BITRSHIFT can be
> done with only one machine cycle (clock tic); the division is a lot more
complex.
>
> BUT !
> this is true only if K is an integer (k = CAST(8E9 AS integer)).
> Otherwise you must add add the conversion time between numeric and
integer.
>
> You can also add a third test : k * .5 sould be faster than k /2
>
> The Foxil
> Old enough to know how microprocessors work !
>
>
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.