앞의 프로파일러 통계 표를 보면 이 코드에서 누적 시간으로 CPU를 가장 많이 사용한 함수는 insert_value 함수다. 이 함수를 bisect 내장 모듈(아이템 102 “정렬된 시퀀스를 검색할 때는 bisect를 사용하라”)을 사용해 다시 구현했다.
from bisect import bisect_left
def insert_value(array, value):
i = bisect_left(array, value)
array.insert(i, value)