这是我的测试脚本
echo "=====ss===="
time ss -o state established | wc -l
echo "====netstat===="
time netstat -ant | grep EST | wc -l
,输出为:
[root@lab8106 ~]# ./test_network.sh
=====ss====
268
real 0m0.212s
user 0m0.183s
sys 0m0.033s
====netstat====
169
real 0m0.026s
user 0m0.009s
sys 0m0.025s
因为我读了许多博客,他们说" ss"比#st; netstat"快得多, 但我上面的测试结果让我很困惑。我该怎么做才能深入挖掘它?
答案 0 :(得分:1)
您忘记了def original_app(lag_seq, regular_sequence):
seq = [np.concatenate((np.zeros(x, dtype=np.int), regular_sequence)) for x in lag_seq]
return np.concatenate(seq)
def vectorized_app(lag_seq, regular_sequence):
N = regular_sequence.size
offset_arr = np.cumsum(lag_seq)
idx = np.arange(offset_arr.size)*N + offset_arr
out = np.zeros(idx.max() + N,dtype=regular_sequence.dtype)
np.put(out,idx[:,None] + np.arange(N),regular_sequence)
return out
In [64]: # Setup inputs
...: regular_sequence = np.array([1,2,3,4,5], dtype=np.int)
...: n_iter = 1000
...: lag_mean = 10 # mean length of zeros sequence
...: lag_sd = 1 # standard deviation of zeros sequence length
...:
...: # Sequence of lags lengths
...: lag_seq = [int(round(normalvariate(lag_mean, lag_sd))) for x in range(n_iter)]
...:
In [65]: out1 = original_app(lag_seq, regular_sequence)
In [66]: out2 = vectorized_app(lag_seq, regular_sequence)
In [67]: %timeit original_app(lag_seq, regular_sequence)
100 loops, best of 3: 4.28 ms per loop
In [68]: %timeit vectorized_app(lag_seq, regular_sequence)
1000 loops, best of 3: 294 µs per loop
-n
,因此您可以有效地为每个IP执行反向DNS查找,这肯定会延长执行时间。