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

Function BenchmarkStorage

xenomint/sqlite/sqlite_test.go:453–662  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

451}
452
453func BenchmarkStorage(b *testing.B) {
454 var (
455 st, q, dm, e, src = setupBenchmarkStorage(b)
456
457 tx *sql.Tx
458 dest = dm()
459 read = func(b *testing.B, conn *sql.DB, dest []interface{}) {
460 var err error
461 if err = conn.QueryRow(q, rrkg.next()).Scan(dest...); err != nil {
462 b.Fatalf("failed to query values: %v", err)
463 }
464 }
465 readTx = func(b *testing.B, i int, conn *sql.DB, dest []interface{}) {
466 var err error
467 if i%benchmarkQueriesPerTx == 0 {
468 if tx, err = conn.Begin(); err != nil {
469 b.Fatalf("failed to begin transaction: %v", err)
470 }
471 }
472 // Query in [n, 2n-1] key space
473 if err = tx.QueryRow(q, nrkg.next()).Scan(dest...); err != nil && err != sql.ErrNoRows {
474 b.Fatalf("failed to query values: %v", err)
475 }
476 if (i+1)%benchmarkQueriesPerTx == 0 || i == b.N-1 {
477 if err = tx.Rollback(); err != nil {
478 b.Fatalf("failed to close transaction: %v", err)
479 }
480 }
481 }
482 write = func(b *testing.B, conn *sql.DB) {
483 var err error
484 if _, err = conn.Exec(e, src[ipkg.next()]...); err != nil {
485 b.Errorf("failed to execute: %v", err)
486 }
487 }
488 writeTx = func(b *testing.B, i int, conn *sql.DB) {
489 var err error
490 if i%benchmarkQueriesPerTx == 0 {
491 if tx, err = st.Writer().Begin(); err != nil {
492 b.Errorf("failed to begin transaction: %v", err)
493 }
494 }
495 if _, err = tx.Exec(e, src[ipkg.next()]...); err != nil {
496 b.Errorf("failed to execute: %v", err)
497 }
498 if (i+1)%benchmarkQueriesPerTx == 0 || i == b.N-1 {
499 if err = tx.Commit(); err != nil {
500 b.Errorf("failed to commit transaction: %v", err)
501 }
502 }
503 }
504 mixRW = func(b *testing.B, rconn, wconn *sql.DB, dest []interface{}) {
505 if rand.Int()%2 == 0 {
506 read(b, rconn, dest)
507 } else {
508 write(b, wconn)
509 }
510 }

Callers

nothing calls this directly

Calls 15

setupBenchmarkStorageFunction · 0.85
readFunction · 0.85
writeFunction · 0.85
busyWriteFunction · 0.85
busyWriteTxFunction · 0.85
idleWriteTxFunction · 0.85
teardownBenchmarkStorageFunction · 0.85
setupSubBenchmarkStorageFunction · 0.85
QueryRowMethod · 0.80
FatalfMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected