더북(TheBook)

마이크로벤치마크를 실행해서 앞에서 본 socket.recv를 사용하는 방법과 이 방법의 성능을 비교할 수 있다.

def run_test():
    chunk = write_view[byte_offset:byte_offset + size]
    socket.recv_into(chunk)
    
result = (
    timeit.timeit(
        stmt="run_test()",
        globals=globals(),
        number=100,
    ) 
    / 100
)
    
print(f"{result:0.9f} seconds")

 

>>>
0.000033925 seconds