I have a Python function I'm trying to speed up, which just takes a line of tshark output, eg:
'1\t0.000000000\tTCP\t100.0.1.190,111.0.0.2\t35291\t55321\t\t\t56\t20\t··········S·\t36\n'
and assigns the data to variables like so:
arr = line.strip('\n').split("\t")
sip = arr[3].split(',')[0]
dip = arr[3].split(',')[1]
s_flag = 1 if 'S' in arr[10] else '0'
a_flag = 1 if 'A' in arr[10] else '0'
f_flag = 1 if 'F' in arr[10] else '0'
r_flag = 1 if 'R' in arr[10] else '0'
p_flag = 1 if 'P' in arr[10] else '0'
u_flag = 1 if 'U' in arr[10] else '0'
e_flag = 1 if 'E' in arr[10] else '0'
c_flag = 1 if 'C' in arr[10] else '0'
What is a way to speed this up using Cython? I'm thinking of casting the results of line.strip('\n').split("\t") to a numpy array since I heard it's faster than Python lists in Cython? How else can I speed this up? eg:
import numpy
cimport numpy
arr = np.array(line.strip('\n').split("\t"))
Will this work? Thank you in advance!