MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / benchDB

Function benchDB

cmd/cql-minerd/integration_test.go:706–799  ·  view source on GitHub ↗
(b *testing.B, db *sql.DB, createDB bool)

Source from the content-addressed store, hash-verified

704}
705
706func benchDB(b *testing.B, db *sql.DB, createDB bool) {
707 var err error
708 if createDB {
709 prepareBenchTable(db)
710 }
711
712 cleanBenchTable(db)
713
714 var i int64
715 i = -1
716 db.SetMaxIdleConns(256)
717
718 b.Run(makeBenchName("INSERT"), func(b *testing.B) {
719 b.ResetTimer()
720 b.RunParallel(func(pb *testing.PB) {
721 for pb.Next() {
722 ii := atomic.AddInt64(&i, 1)
723 index := ROWSTART + ii
724 //start := time.Now()
725
726 ctx, task := trace.NewTask(context.Background(), "BenchInsert")
727
728 _, err = db.ExecContext(ctx, "INSERT INTO "+TABLENAME+" ( k, v1 ) VALUES"+
729 "(?, ?)", index, ii,
730 )
731 //log.Warnf("insert index = %d %v", index, time.Since(start))
732 for err != nil && err.Error() == sqlite3.ErrBusy.Error() {
733 // retry forever
734 log.Warnf("index = %d retried", index)
735 _, err = db.ExecContext(ctx, "INSERT INTO "+TABLENAME+" ( k, v1 ) VALUES"+
736 "(?, ?)", index, ii,
737 )
738 }
739 if err != nil {
740 b.Fatal(err)
741 }
742
743 task.End()
744 }
745 })
746 })
747
748 rowCount := db.QueryRow("SELECT COUNT(1) FROM " + TABLENAME)
749 var count int64
750 err = rowCount.Scan(&count)
751 if err != nil {
752 b.Fatal(err)
753 }
754 log.Warnf("row Count: %v", count)
755
756 b.Run(makeBenchName("SELECT"), func(b *testing.B) {
757 b.ResetTimer()
758 b.RunParallel(func(pb *testing.PB) {
759 for pb.Next() {
760 var index int64
761 if createDB { //only data by insert
762 index = rand.Int63n(count-1) + ROWSTART
763 } else { //has data before ROWSTART

Callers 3

benchMinerFunction · 0.85
BenchmarkSQLiteFunction · 0.85

Calls 15

NewTaskFunction · 0.92
WarnfFunction · 0.92
ErrorfFunction · 0.92
InfofFunction · 0.92
prepareBenchTableFunction · 0.85
cleanBenchTableFunction · 0.85
makeBenchNameFunction · 0.85
ErrorMethod · 0.80
FatalMethod · 0.80
QueryRowMethod · 0.80
ErrorfMethod · 0.80
ExecContextMethod · 0.65

Tested by

no test coverage detected