INSERT GRAPHIC HERE (include hyperlink in image)
Subtitle or Short Description Goes Here
type model struct { | |
ID int `dbq:"id" gorm:"column:id" db:"id"` | |
Name string `dbq:"name" gorm:"column:name" db:"name"` | |
Email string `dbq:"email" gorm:"column:email" db:"email"` | |
} | |
// Recommended by dbq | |
func (m *model) ScanFast() []interface{} { | |
return []interface{}{&m.ID, &m.Name, &m.Email} | |
} |
g, err := gorm.Open("mysql", db) | |
if err != nil { | |
panic(err) | |
} | |
b.Run(fmt.Sprintf("gorm limit:%d", lim), func(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
var res = []model{} | |
err := g.Order("id").Limit(lim).Find(&res).Error |
for i := 0; i < b.N; i++ { | |
db := sqlx.NewDb(db, "mysql") | |
q := fmt.Sprintf("SELECT id, name, email FROM tests ORDER BY id LIMIT %d", lim) | |
res := []model{} | |
err := db.Select(&res, q) | |
if err != nil { | |
b.Fatal(err) | |
} | |
} |
for i := 0; i < b.N; i++ { | |
q := fmt.Sprintf("SELECT id, name, email FROM tests ORDER BY id LIMIT %d", lim) | |
res, err := dbq.Qs(ctx, db, q, model{}, nil) | |
if err != nil { | |
b.Fatal(err) | |
} | |
} |
func Benchmark(b *testing.B) { | |
setup() | |
defer cleanup() | |
limits := []int{ | |
5, | |
50, | |
500, | |
10000, | |
} |
var db *sql.DB | |
func init() { | |
db, _ = sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", user, pword, host, port, dbname)) | |
db.SetMaxOpenConns(1) | |
err := db.Ping() | |
if err != nil { | |
panic(err) | |
} | |
} |
var db *sql.DB | |
// Add DB credentials here | |
var ( | |
user string = "" | |
pword string = "" | |
host string = "" | |
port string = "" | |
dbname string = "" | |
) |
import Foundation | |
/// Protocol for NSLocking objects that also provide tryLock() | |
public protocol TryLockable: NSLocking { | |
func tryLock() -> Bool | |
} | |
// These Cocoa classes have tryLock() | |
extension NSLock: TryLockable {} | |
extension NSRecursiveLock: TryLockable {} |