I'm working with 64 bit unsigned integers and after bit shifting comparing the value before decoding the rest of the bit values. I'm iterating over millions of values and trying to minimize process time.
The issue is bit shifting is not supported with uint64 nor numpy-uint64. I'm trying to avoid using int64 to avoid negative values.
example data: 0x8204000000000080 after shifting(word>> 60): =-8 #but comparing to 0x8
looping one million times and seeing how long it takes it was found that of all methods the '>>' shift operator was the most expedient with the next best option to call the abs() function. Is there a better more expedient solution for this?
Loop code:
import numpy as np
import time
start_time= time.time()
for i in range(1000000):
x= np.int64(-1)
x=np.right_shift(x,60)
print (time.time()-start_time)
start_time= time.time()
for i in range(1000000):
x= np.uint64(-1)
x=int(x/(2**60))
print (time.time()-start_time)
start_time= time.time()
for i in range(1000000):
x= np.int64(-1)
x=abs(x>>60)
print (time.time()-start_time)
start_time= time.time()
for i in range(1000000):
x= np.int64(-1)
x= x>>60
print (time.time()-start_time)
Output:
2.055999994277954
3.1540000438690186
0.619999885559082
0.5810000896453857