Skip to main content

ประสิทธิภาพ

ตัวเลข throughput และความแม่นยำของ kham v0.8.2 วัดบน Apple M-series (arm64) benchmark ทั้งหมดรันด้วย --release และ LTO เปิดใช้งาน

สภาพแวดล้อม

CPU Apple M-series (arm64)
OS macOS
Rust 1.85+ stable, LTO เปิดใช้งาน
Profile release
dictionary ในตัว 62,102 คำ · 670,460 DARTS states · 5.1 MiB
ตาราง TNC frequency 106,125 รายการ

รันเองได้: cargo bench -p kham-core — รายงาน HTML ที่ target/criterion/report/index.html

ความแม่นยำ

Precision / Recall / F1 ระดับขอบเขตคำเทียบกับ gold corpus แบบ CC0 (kham-core/testdata/) และเปรียบเทียบกับ PyThaiNLP word_tokenize(engine='newmm') บน 39 ประโยค

1.000
Micro F1
เทียบกับ CC0 gold corpus (228 test cases)
94.9%
ประโยคที่ตรงกัน
37/39 เทียบกับ PyThaiNLP newmm
0
ความต่างที่แท้จริง
2 รายการที่เหลือเป็นข้อผิดพลาดของ PyThaiNLP
วิธีรันเอง:
cargo run -p kham-bench-accuracy
cargo run -p kham-bench-accuracy -- --threshold 0.95   # CI gate
cargo run -p kham-bench-accuracy -- --verbose           # แสดงกรณีที่ผิดพลาด

Throughput การตัดคำ

ข้อความภาษาไทยล้วน, dictionary ในตัว, benchmark segment/by_length

ขนาด inputBytesเวลา (median)Throughput
สั้น (short)39 B1.12 µs33.2 MiB/s
กลาง (medium)180 B5.09 µs33.7 MiB/s
ยาว (long)540 B14.95 µs34.4 MiB/s

หลายภาษาผสมกัน (Mixed-script)

ภาษาไทย + ภาษาอังกฤษ + ตัวเลขในข้อความเดียวกัน — segment/mixed

InputBytesเวลา (median)Throughput
sparse (ธนาคาร100แห่ง)33 B948 ns33.2 MiB/s
medium (หลาย boundary)79 B2.23 µs33.8 MiB/s
dense (สลับภาษา)31 B770 ns38.4 MiB/s

Normalization

Unicode normalization (จัดเรียงสระลอย, ลบวรรณยุกต์ซ้ำ, NFC) — normalize/thai

ขนาด inputBytesเวลา (median)Throughput
สั้น39 B107.6 ns345 MiB/s
กลาง180 B285.9 ns600 MiB/s
ยาว540 B743.7 ns692 MiB/s

SQLite FTS5 Extension

Criterion benchmarks ผ่าน rusqlite, in-memory database, FTS5 เปิดใช้งาน pipeline ต่อการเรียก xTokenize: normalize → NE → stopword → POS → synonym → RTGS

Throughput การ index (INSERT)

BenchmarkInputขนาดเวลา (median)Throughput
index/single/shortกินข้าวกับปลา39 B20.2 µs1.84 MiB/s
index/single/mediumข้อความภาษาไทย ~60 chars180 B64.8 µs2.65 MiB/s
index/single/long3× medium540 B122.3 µs4.21 MiB/s
index/batch_100/short100 × short3.9 KB813 µs (8.1 µs/doc)4.57 MiB/s
index/batch_100/medium100 × medium18.0 KB3.67 ms (36.7 µs/doc)4.68 MiB/s
index/batch_100/long100 × long54.0 KB8.84 ms (88.4 µs/doc)5.82 MiB/s

Latency การค้นหา

ตาราง 1,000 แถว ข้อความขนาดกลาง

BenchmarkQueryแถวผลลัพธ์เวลา (median)
query/single_word/thai_commonข้าว1,0004.28 µs
query/single_word/thai_rareปลา1,000139.7 µs
query/single_word/number10002.00 µs
query/single_word/latinhello02.10 µs
query/snippetข้าว (LIMIT 10)104.24 µs

PostgreSQL FTS Extension

วัดภายใน Docker (PostgreSQL 17, Linux ARM64) ผ่าน make -C kham-pg bench pipeline ต่อการเรียก to_tsvector: normalize → segment → NE tag → lk82 soundex → RTGS romanization

Throughput ของ to_tsvector & plainto_tsquery

batch throughput ผ่าน generate_series หมุนเวียน 3 input ต่อขนาด เพื่อป้องกัน function-result cache ของ PostgreSQL pipeline ต่อการเรียก: normalize → segment → NE tag → lk82 soundex → RTGS romanization

การดำเนินการขนาด documentops/sµs/op
to_tsvector ขนาดเล็ก~63 B15,146,9250.066
to_tsvector ขนาดกลาง~630 B14,367,8160.070
to_tsvector ขนาดใหญ่~6.3 KB 8,771,9300.114
plainto_tsquery (1 คำ)15,964,2400.063
plainto_tsquery (3 คำ)16,425,7560.061
วิธีรันเอง:
make -C kham-pg bench