package main import ( "TsDB2/DB" "fmt" "os" "time" ) type Record struct { DB.BaseModel Name string `vrtx:"maxlen:32"` } const dbPath = "commit_preset_test.db" func testPreset(preset string, rows int) { os.Remove(dbPath) db, err := DB.Open(dbPath) if err != nil { panic(err) } db.SetCommitPreset(preset) tbl, err := DB.UseTable[Record](db, "test") if err != nil { panic(err) } start := time.Now() for i := 1; i <= rows; i++ { tbl.Insert(&Record{ Name: fmt.Sprintf("Emp%07d", i), }) } elapsed := time.Since(start) fi, _ := os.Stat(dbPath) fileSize := float64(fi.Size()) / 1024 / 1024 fmt.Printf(" %-8s | %6d行 | %5.2fs | %5.1fMB\n", preset, rows, elapsed.Seconds(), fileSize) db.Close() } func main() { fmt.Println("==============================================") fmt.Println(" 提交策略预设性能对比测试") fmt.Print("==============================================\n\n") rows := 10000 fmt.Printf("测试场景: 插入 %d 行数据\n\n", rows) fmt.Println(" 预设类型 | 行数 | 耗时 | 文件大小") fmt.Println(" ---------+--------+--------+----------") testPreset("batch", rows) // 离线批量导入 testPreset("online", rows) // 在线业务 testPreset("safe", rows) // 关键数据 fmt.Println("\n说明:") fmt.Println(" - batch: 高吞吐,适合离线导入 (断电风险: ~10,000行)") fmt.Println(" - online: 平衡性能和安全 (断电风险: ~2,000行)") fmt.Println(" - safe: 最高安全,适合关键业务 (断电风险: ~400行)") fmt.Println("\n选择建议:") fmt.Println(" - 批量导入脚本 → batch") fmt.Println(" - Web/API 服务 → online") fmt.Println(" - 金融/医疗数据 → safe") }