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

Function idleWriteTx

xenomint/sqlite/sqlite_test.go:873–920  ·  view source on GitHub ↗
(
	b *testing.B,
	wg *sync.WaitGroup, sc <-chan struct{},
	st xi.Storage, kg keygen, e string, src [][]interface{},
)

Source from the content-addressed store, hash-verified

871}
872
873func idleWriteTx(
874 b *testing.B,
875 wg *sync.WaitGroup, sc <-chan struct{},
876 st xi.Storage, kg keygen, e string, src [][]interface{},
877) {
878 const writeIntlMS = 1
879 var (
880 tx *sql.Tx
881 err error
882 ticker = time.NewTicker(writeIntlMS * time.Millisecond)
883 )
884 defer func() {
885 ticker.Stop()
886 wg.Done()
887 }()
888 for i := 0; ; i++ {
889 // Begin
890 if i%benchmarkQueriesPerTx == 0 {
891 if tx, err = st.Writer().Begin(); err != nil {
892 b.Errorf("failed to begin transaction: %v", err)
893 }
894 }
895 // Exec
896 select {
897 case <-ticker.C:
898 // Exec
899 if _, err = tx.Exec(e, src[kg.next()]...); err != nil {
900 b.Errorf("failed to execute: %v", err)
901 }
902 case <-sc:
903 // Also commit on exiting
904 if tx != nil {
905 if err = tx.Commit(); err != nil {
906 b.Errorf("failed to commit transaction: %v", err)
907 }
908 tx = nil
909 }
910 return
911 }
912 // Commit
913 if (i+1)%benchmarkQueriesPerTx == 0 {
914 if err = tx.Commit(); err != nil {
915 b.Errorf("failed to commit transaction: %v", err)
916 }
917 tx = nil
918 }
919 }
920}
921
922// GR is a get reader function passed to benchmark helper.
923//type GR func(xi.Storage) *sql.DB

Callers 1

BenchmarkStorageFunction · 0.85

Calls 7

ErrorfMethod · 0.80
WriterMethod · 0.65
ExecMethod · 0.65
nextMethod · 0.65
CommitMethod · 0.65
StopMethod · 0.45
BeginMethod · 0.45

Tested by

no test coverage detected