Skip to content

Instantly share code, notes, and snippets.

@pjebs
pjebs / benchmark-model.go
Last active June 26, 2020 00:02
benchmark model
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}
}
@pjebs
pjebs / gorm_benchmark.go
Last active June 25, 2020 03:58
gorm benchmark
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
@pjebs
pjebs / sqlx_benchmark.go
Last active June 25, 2020 03:58
sqlx benchmark
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)
}
}
@pjebs
pjebs / dbq_benchmark.go
Created June 25, 2020 03:53
dbq benchmark
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)
}
}
@pjebs
pjebs / benchmark-structure.go
Created June 25, 2020 02:23
go benchmark structure
func Benchmark(b *testing.B) {
setup()
defer cleanup()
limits := []int{
5,
50,
500,
10000,
}
@pjebs
pjebs / dbq_setup.go
Last active July 2, 2020 05:47
go benchmarking: setup and cleanup
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)
}
}
@pjebs
pjebs / dbq_setup.go
Created June 25, 2020 01:54
go benchmarking: setup and cleanup
var db *sql.DB
// Add DB credentials here
var (
user string = ""
pword string = ""
host string = ""
port string = ""
dbname string = ""
)
@pjebs
pjebs / sampleREADME.md
Created June 12, 2020 00:28 — forked from FrancesCoronel/sampleREADME.md
A sample README for all your GitHub projects.

FVCproductions

INSERT GRAPHIC HERE (include hyperlink in image)

Repository Title Goes Here

Subtitle or Short Description Goes Here

@pjebs
pjebs / locking.swift
Created February 25, 2016 10:51 — forked from kristopherjohnson/locking.swift
Simple synchronization functions for Swift, wrapping the Cocoa NSLocking classes
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 {}