Beispiel #1
0
//-----------------------------------------------------------------------------
// Set map VS Set struct
//-----------------------------------------------------------------------------
//TODO:work in progress
func BenchmarkSetStruct(b *testing.B) {
	tu.SkipBLog(b)

	type Person struct {
		UserId    int    `db:"id"`
		FirstName string `db:"first_name"`
		LastName  string `db:"first_name"`
	}

	b.ResetTimer()
	newMySQL()
	//db := getMySQL().Db

	//single data
	var person Person
	sql := "SELECT user_id, first_name, last_name FROM t_users WHERE delete_flg=?"

	for i := 0; i < b.N; i++ {
		//
		getMySQL().Db.SelectIns(sql, "0").ScanOne(&person)
		//db.SelectSQLAllFieldIns(sql, "0")
		//
	}
	getMySQL().Db.Close()
	b.StopTimer()

	//20000000	        87.1 ns/op (93.8 ns/op)
}
Beispiel #2
0
//-----------------------------------------------------------------------------
// ComplicatedSQL VS MultiSimpleSQL(Don't use it)
//-----------------------------------------------------------------------------
func BenchmarkComplicatedSQL(b *testing.B) {
	tu.SkipBLog(b)

	b.ResetTimer()
	newMySQL()
	for i := 0; i < b.N; i++ {
		//
		_, _ = getMySQL().getComplicatedSQL()
		//
	}
	getMySQL().Db.Close()
	b.StopTimer()
	//94.2 ns/op
}
Beispiel #3
0
func BenchmarkOpenClose(b *testing.B) {
	tu.SkipBLog(b)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		newMySQL()
		//performance for select query
		_, _ = getMySQL().getUserList()
		//
		getMySQL().Db.Close()
	}
	b.StopTimer()
	//100000	     24609 ns/op (19178 ns/op)
	//ok  	github.com/hiromaily/golibs/db/mysql	2.730s
}
Beispiel #4
0
//-----------------------------------------------------------------------------
// Bench
//-----------------------------------------------------------------------------
func BenchmarkFlag(b *testing.B) {
	tu.SkipBLog(b)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		for i, v := range os.Args {
			lg.Debugf("os.Args[%d]: %v", i, v)
			//os.Args[0]: /var/folders/zw/fjz6w8n17c7_m47wjbzdqw1c0000gn/T/go-build666805607/github.com/hiromaily/golibs/flag/_test/flag.test
			//os.Args[1]: -test.bench=.
			//os.Args[2]: -test.benchmem=true
		}
	}
	b.StopTimer()
	//2654 ns/op
}
Beispiel #5
0
//-----------------------------------------------------------------------------
// NoCache VS Using Redis
//   Use for only heavy query
//-----------------------------------------------------------------------------
func BenchmarkCacheResponse(b *testing.B) {
	tu.SkipBLog(b)

	b.ResetTimer()
	newMySQL()
	for i := 0; i < b.N; i++ {
		//
		_, _ = getMySQL().getUserListOnCache()
		//
	}
	getMySQL().Db.Close()
	b.StopTimer()

	//20000000	        87.1 ns/op (93.8 ns/op)
	//ok  	github.com/hiromaily/golibs/db/mysql	1.885s
}
Beispiel #6
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//Benchmark
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
func BenchmarkSetData(b *testing.B) {
	//b.Skip(fmt.Sprintf("skipping %s", r.CurrentFunc(1)))
	tu.SkipBLog(b)

	GetRedis().Connection(0)
	c := GetRedis().Conn

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		c.Do("SET", "key1", 10)
	}
	b.StopTimer()

	dropDatabase()
	//35143 ns/op
}
Beispiel #7
0
func BenchmarkMultiSimpleSQL(b *testing.B) {
	tu.SkipBLog(b)

	b.ResetTimer()
	newMySQL()
	for i := 0; i < b.N; i++ {
		//
		_, _ = getMySQL().getSimpleSQL1()
		_, _ = getMySQL().getSimpleSQL2(9)
		_, _ = getMySQL().getSimpleSQL2(13)
		_, _ = getMySQL().getSimpleSQL2(21)
		//
	}
	getMySQL().Db.Close()
	b.StopTimer()
	//375 ns/op
}
Beispiel #8
0
//-----------------------------------------------------------------------------
// Benchmark
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// ConnectionPool VS Not use it
//-----------------------------------------------------------------------------
func BenchmarkConnectionPool(b *testing.B) {
	tu.SkipBLog(b)

	//BenchmarkConnectionPool-4
	b.ResetTimer()
	newMySQL()
	getMySQL().Db.SetMaxIdleConns(100)
	getMySQL().Db.SetMaxOpenConns(10000)
	for i := 0; i < b.N; i++ {
		//
		_, _ = getMySQL().getUserList()
		//
	}
	getMySQL().Db.Close()
	b.StopTimer()

	//20000000	        87.1 ns/op (93.8 ns/op)
	//ok  	github.com/hiromaily/golibs/db/mysql	1.885s
}