Skip to content

Commit

Permalink
add database/sql
Browse files Browse the repository at this point in the history
  • Loading branch information
amirrezaask committed Jun 1, 2022
1 parent 2f3de03 commit ee0cc59
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion benchmark/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ type User struct {
}

var (
db *sql.DB
gormDB *gorm.DB
)

func setupGolobby() {
db, err := sql.Open("sqlite3", ":memory:")
var err error
db, err = sql.Open("sqlite3", ":memory:")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -69,6 +71,19 @@ func BenchmarkGolobby(t *testing.B) {
}
}

func BenchmarkStdSQL(t *testing.B) {
setupGolobby()
t.ResetTimer()
for i := 0; i < t.N; i++ {
var user User
user.Username = "amir" + fmt.Sprint(i)
_, err := db.Exec(`INSERT INTO users (username) VALUES (?)`, user.Username)
if err != nil {
panic(err)
}
}
}

type User2 struct {
gorm.Model
ID int64 `json:"id"`
Expand Down

0 comments on commit ee0cc59

Please sign in to comment.