psyco 의 성능 증가 효과는 순수 python 코드에서만 이루어진다라고 들어서
지금까지 작업하면서 가장 느린 성능을 보여주었던 difflib 을 이용해 테스트해보기로 했다.
테스트용 파일은 독일 버전 아이템 테이블과 중국 버전 아이템 테이블
거의 모든 라인에 변화가 있는 상태이다. 처음에는 전체를 체크해보려고 했으나;
너무 느려서(-_-); 300라인만 테스트해보기로 했다.
# 기본 소스 약 12.5 초
from difflib import Differ
def main():
old_lines = open("old.txt").read().splitlines()[:300]
new_lines = open("new.txt").read().splitlines()[:300]
differ = Differ()
diff_lines = differ.compare(old_lines, new_lines)
return [line for line in diff_lines if line[0] != " "]
import time
t1 = time.clock()
main()
t2 = time.clock()
print t2-t1
겨우 300라인인데 엄청난 속도이다. 이걸 왜 순수 파이썬으로 작성했는지 의문이다-_-
# psyco 사용 약 3.5초
import psyco
psyco.full()
def main():
old_lines = open("old.txt").read().splitlines()[:300]
new_lines = open("new.txt").read().splitlines()[:300]
differ = Differ()
diff_lines = differ.compare(old_lines, new_lines)
return [line for line in diff_lines if line[0] != " "]
import time
t1 = time.clock()
main()
t2 = time.clock()
print t2-t1
딱 두줄 추가로 4배에 가까운 성능 향상을 보여주었다.
psyco.full() 을 사용하면 시작 속도가 느리므로
psyco.bind 나 psyco.proxy 등을 사용하면 좋다는 이야기가 있으나 아직 확인중이다.


python 을 좋아하는 게임 프로그래머