C.W.K.
Stream
Lesson 09 of 10 · published

거짓말 안 하는 벤치마크

~12 min · benchmarking, performance, measurement

Level 0Scout
0 XP0/80 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

벤치마크 거짓말 만드는 3 가지

인터넷의 거의 모든 가벼운 SQLite 벤치마크가 다음 중 적어도 하나로 틀려. 본인 측정에선 피해.

  1. Cold vs warm cache — 첫 run 은 디스크 read, 이후는 OS page cache hit. 어느 케이스 측정인지 결정 + 의도적으로 warm/cool.
  2. Per-statement transaction — autocommit write 가 row 마다 fsync 한 번. Transaction 없는 10k INSERT 루프는 SQLite write 속도 측정 X, 파일시스템 sync latency 측정.
  3. 작은 dataset — 100 row 면 모든 DB 빠름. 현실적 row count 로 측정; 이상적으로는 production 스케일의 multiple.
Principle: 어떤 PRAGMA 설정됐는지, dataset 모양이 뭔지, cache 가 warm 이었는지 안 적힌 벤치마크는 벤치마크 아냐. 항상 그 셋 문서화.

Code

합리적 Python micro-benchmark·python
import sqlite3, time, os, statistics

def setup():
    if os.path.exists('bench.db'):
        os.remove('bench.db')
    conn = sqlite3.connect('bench.db')
    conn.execute('PRAGMA journal_mode = WAL')
    conn.execute('PRAGMA synchronous = NORMAL')
    conn.execute('CREATE TABLE t(id INTEGER PRIMARY KEY, v TEXT)')
    return conn

def bench_inserts(n: int) -> float:
    conn = setup()
    rows = [(f'v{i}',) for i in range(n)]
    start = time.perf_counter()
    with conn:
        conn.executemany('INSERT INTO t(v) VALUES (?)', rows)
    return time.perf_counter() - start

durations = [bench_inserts(10000) for _ in range(5)]
print(f'10k inserts: median {statistics.median(durations)*1000:.1f} ms')

External links

Exercise

벤치마크 harness 빌드: (1) executemany + transaction vs autocommit per row 의 bulk insert 처리량, (2) cold vs warm cache 의 point-read 처리량, (3) 인덱스 유무로 동일 point-read. 모든 PRAGMA 설정과 dataset 모양 문서화. 스크립트 reproducible 하게.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.