Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Commit

Permalink
add benchmark tests for mssql
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Dec 26, 2013
1 parent 3f2328d commit d1a0338
Showing 1 changed file with 75 additions and 7 deletions.
82 changes: 75 additions & 7 deletions mssql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ package xorm
// +build windows

import (
"database/sql"
"testing"

_ "github.com/lunny/godbc"
)

/*
CREATE DATABASE IF NOT EXISTS xorm_test CHARACTER SET
utf8 COLLATE utf8_general_ci;
*/
const mssqlConnStr = "driver={SQL Server};Server=192.168.20.135;Database=xorm_test; uid=sa; pwd=1234;"

func newMssqlEngine() (*Engine, error) {
return NewEngine("odbc", "driver={SQL Server};Server=192.168.20.135;Database=xorm_test; uid=sa; pwd=1234;")
return NewEngine("odbc", mssqlConnStr)
}

func TestMssql(t *testing.T) {
Expand Down Expand Up @@ -51,7 +49,41 @@ func TestMssqlWithCache(t *testing.T) {
testAll2(engine, t)
}

func BenchmarkMssqlNoCache(t *testing.B) {
func newMssqlDriverDB() (*sql.DB, error) {
return sql.Open("odbc", mssqlConnStr)
}

const (
createTableMssql = `IF NOT EXISTS (SELECT [name] FROM sys.tables WHERE [name] = 'big_struct' ) CREATE TABLE
"big_struct" ("id" BIGINT PRIMARY KEY IDENTITY NOT NULL, "name" VARCHAR(255) NULL, "title" VARCHAR(255) NULL,
"age" VARCHAR(255) NULL, "alias" VARCHAR(255) NULL, "nick_name" VARCHAR(255) NULL);
`

dropTableMssql = "IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'big_struct') and OBJECTPROPERTY(id, N'IsUserTable') = 1) DROP TABLE IF EXISTS `big_struct`;"
)

func BenchmarkMssqlDriverInsert(t *testing.B) {
doBenchDriver(newMssqlDriverDB, createTableMssql, dropTableMssql,
doBenchDriverInsert, t)
}

func BenchmarkMssqlDriverFind(t *testing.B) {
doBenchDriver(newMssqlDriverDB, createTableMssql, dropTableMssql,
doBenchDriverFind, t)
}

func BenchmarkMssqlNoCacheInsert(t *testing.B) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
//engine.ShowSQL = true
doBenchInsert(engine, t)
}

func BenchmarkMssqlNoCacheFind(t *testing.B) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
Expand All @@ -62,13 +94,49 @@ func BenchmarkMssqlNoCache(t *testing.B) {
doBenchFind(engine, t)
}

func BenchmarkMssqlCache(t *testing.B) {
func BenchmarkMssqlNoCacheFindPtr(t *testing.B) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
//engine.ShowSQL = true
doBenchFindPtr(engine, t)
}

func BenchmarkMssqlCacheInsert(t *testing.B) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))

doBenchInsert(engine, t)
}

func BenchmarkMssqlCacheFind(t *testing.B) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))

doBenchFind(engine, t)
}

func BenchmarkMssqlCacheFindPtr(t *testing.B) {
engine, err := newMssqlEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))

doBenchFindPtr(engine, t)
}

0 comments on commit d1a0338

Please sign in to comment.