블로그 이미지
.
속눈썹맨

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

cat, cp, getline, gzip 속도 test

2004. 7. 14. 10:59 | Posted by 속눈썹맨
cat, cp, getline 속도 test
test 환경
$ g++ --version
g++ (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
$ uname -a
Linux search124.sayclub.com 2.4.20-20.9ns1smp #1 SMP Tue Oct 7 14:13:18 KST 2003 i686 i686 i386 GNU/Linux
$ export LANG=C

input file size : 1,286,935,566 = 1.2Gbytes

프로그램 성능 비교
0. cat
1. getline(char*), char*만 쓴 경우
2. getline(string&), string만 쓴경우
3. class inheritance, getline(char*), string을 쓴 경우
4. class inheritance, getline(char*), char*을 쓴 경우
5. class inheritance, getline(string&), string을 쓴 경우
6. cp
7. gzip -c | gzip -dc

t0 test
real 1m15.837s
user 0m0.220s
sys 0m12.450s

t1 test
real 1m38.106s
user 0m7.270s
sys 0m16.990s

t2 test
real 9m20.131s
user 6m18.900s
sys 2m37.820s

t3 test
real 1m40.530s
user 0m12.710s
sys 0m18.010s

t4 test
real 1m40.751s
user 0m8.170s
sys 0m17.540s

t5 test
real 9m29.418s
user 6m29.610s
sys 2m36.500s

t6 test
real 1m33.474s
user 0m0.170s
sys 0m12.730s

t7 test
real 2m28.825s
user 1m26.190s
sys 0m20.480s

결론

본인이 c로 짠 프로그램과 unix의 cp는 성능 차이가 없음.
getline(char*)도 속도는 같음
class inheritance, std::string으로 복사하는 것도 그리 overhead가 되지 않음.

속도가 문제가 되는 곳은 getline(string&)임. std::getline은 I/O 시간이
10배 정도 더 소요되고 있음.
(printf와 cout의 차이 정도 됨.)