<commit_before>// Copyright 2015 by caixw, All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.

package test

import (
	"testing"

	"github.com/issue9/assert"
)

// BenchmarkDB_Insert	    5000	    234033 ns/op
func BenchmarkDB_Insert(b *testing.B) {
	a := assert.New(b)

	m := &bench{
		Name: "name",
		Pass: "<PASSWORD>",
		Site: "http://www.github.com/issue9/orm",
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	a.NotError(db.Create(&bench{}))

	for i := 0; i < b.N; i++ {
		a.NotError(db.Insert(m))
	}
}

// BenchmarkDB_MultInsert	      50	  23436852 ns/op
func BenchmarkDB_MultInsert(b *testing.B) {
	a := assert.New(b)

	ms := make([]interface{}, 0, 100)
	for i := 0; i < cap(ms); i++ {
		ms = append(ms, &bench{
			Name: "name",
			Pass: "<PASSWORD>",
			Site: "http://www.github.com/issue9/orm",
		})
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	a.NotError(db.Create(&bench{}))

	for i := 0; i < b.N; i++ {
		a.NotError(db.Insert(ms...))
	}
}

// BenchmarkDB_Update	    5000	    290209 ns/op
func BenchmarkDB_Update(b *testing.B) {
	a := assert.New(b)

	m := &bench{
		Name: "name",
		Pass: "<PASSWORD>",
		Site: "http://www.github.com/issue9/orm",
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	// 构造数据
	a.NotError(db.Create(&bench{}))
	a.NotError(db.Insert(m))

	m.ID = 1 // 自增，从1开始
	for i := 0; i < b.N; i++ {
		a.NotError(db.Update(m))
	}
}

// BenchmarkDB_MultUpdate	      50	  28662471 ns/op
func BenchmarkDB_MultUpdate(b *testing.B) {
	a := assert.New(b)

	ms := make([]interface{}, 0, 100)
	for i := 0; i < cap(ms); i++ {
		ms = append(ms, &bench{
			Name: "name",
			Pass: "<PASSWORD>",
			Site: "http://www.github.com/issue9/orm",
		})
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	// 构造数据
	a.NotError(db.Create(&bench{}))
	a.NotError(db.Insert(ms...))

	i := 0
	for _, m := range ms {
		i++
		m.(*bench).ID = i
	}

	for i := 0; i < b.N; i++ {
		a.NotError(db.Update(ms...))
	}
}

// BenchmarkDB_Select	   10000	    181897 ns/op
func BenchmarkDB_Select(b *testing.B) {
	a := assert.New(b)

	m := &bench{
		Name: "name",
		Pass: "<PASSWORD>",
		Site: "http://www.github.com/issue9/orm",
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	a.NotError(db.Create(&bench{}))
	a.NotError(db.Insert(m))

	m.ID = 1
	for i := 0; i < b.N; i++ {
		a.NotError(db.Select(m))
	}
}

// BenchmarkDB_MultSelect	     100	  18494929 ns/op
func BenchmarkDB_MultSelect(b *testing.B) {
	a := assert.New(b)

	ms := make([]interface{}, 0, 100)
	for i := 0; i < cap(ms); i++ {
		ms = append(ms, &bench{
			Name: "name",
			Pass: "<PASSWORD>",
			Site: "http://www.github.com/issue9/orm",
		})
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	// 构造数据
	a.NotError(db.Create(&bench{}))
	a.NotError(db.Insert(ms...))

	i := 0
	for _, m := range ms {
		i++
		m.(*bench).ID = i
	}

	for i := 0; i < b.N; i++ {
		a.NotError(db.Select(ms...))
	}
}
<commit_msg>添加两段where测试代码<commit_after>// Copyright 2015 by caixw, All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.

package test

import (
	"testing"

	"github.com/issue9/assert"
)

// mysql: BenchmarkDB_Insert	    5000	    234033 ns/op
func BenchmarkDB_Insert(b *testing.B) {
	a := assert.New(b)

	m := &bench{
		Name: "name",
		Pass: "<PASSWORD>",
		Site: "http://www.github.com/issue9/orm",
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	a.NotError(db.Create(&bench{}))

	for i := 0; i < b.N; i++ {
		a.NotError(db.Insert(m))
	}
}

// mysql: BenchmarkDB_MultInsert	      50	  23436852 ns/op
func BenchmarkDB_MultInsert(b *testing.B) {
	a := assert.New(b)

	ms := make([]interface{}, 0, 100)
	for i := 0; i < cap(ms); i++ {
		ms = append(ms, &bench{
			Name: "name",
			Pass: "<PASSWORD>",
			Site: "http://www.github.com/issue9/orm",
		})
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	a.NotError(db.Create(&bench{}))

	for i := 0; i < b.N; i++ {
		a.NotError(db.Insert(ms...))
	}
}

// mysql: BenchmarkDB_Update	    5000	    290209 ns/op
func BenchmarkDB_Update(b *testing.B) {
	a := assert.New(b)

	m := &bench{
		Name: "name",
		Pass: "<PASSWORD>",
		Site: "http://www.github.com/issue9/orm",
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	// 构造数据
	a.NotError(db.Create(&bench{}))
	a.NotError(db.Insert(m))

	m.ID = 1 // 自增，从1开始
	for i := 0; i < b.N; i++ {
		a.NotError(db.Update(m))
	}
}

// mysql: BenchmarkDB_MultUpdate	      50	  28662471 ns/op
func BenchmarkDB_MultUpdate(b *testing.B) {
	a := assert.New(b)

	ms := make([]interface{}, 0, 100)
	for i := 0; i < cap(ms); i++ {
		ms = append(ms, &bench{
			Name: "name",
			Pass: "<PASSWORD>",
			Site: "http://www.github.com/issue9/orm",
		})
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	// 构造数据
	a.NotError(db.Create(&bench{}))
	a.NotError(db.Insert(ms...))

	i := 0
	for _, m := range ms {
		i++
		m.(*bench).ID = i
	}

	for i := 0; i < b.N; i++ {
		a.NotError(db.Update(ms...))
	}
}

// mysql: BenchmarkDB_Select	   10000	    181897 ns/op
func BenchmarkDB_Select(b *testing.B) {
	a := assert.New(b)

	m := &bench{
		Name: "name",
		Pass: "<PASSWORD>",
		Site: "http://www.github.com/issue9/orm",
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	a.NotError(db.Create(&bench{}))
	a.NotError(db.Insert(m))

	m.ID = 1
	for i := 0; i < b.N; i++ {
		a.NotError(db.Select(m))
	}
}

// mysql: BenchmarkDB_MultSelect	     100	  18494929 ns/op
func BenchmarkDB_MultSelect(b *testing.B) {
	a := assert.New(b)

	ms := make([]interface{}, 0, 100)
	for i := 0; i < cap(ms); i++ {
		ms = append(ms, &bench{
			Name: "name",
			Pass: "<PASSWORD>",
			Site: "http://www.github.com/issue9/orm",
		})
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	// 构造数据
	a.NotError(db.Create(&bench{}))
	a.NotError(db.Insert(ms...))

	i := 0
	for _, m := range ms {
		i++
		m.(*bench).ID = i
	}

	for i := 0; i < b.N; i++ {
		a.NotError(db.Select(ms...))
	}
}

// mysql: BenchmarkDB_WhereUpdate	   10000	    169674 ns/op
func BenchmarkDB_WhereUpdate(b *testing.B) {
	a := assert.New(b)

	m := &bench{
		Name: "name",
		Pass: "<PASSWORD>",
		Site: "http://www.github.com/issue9/orm",
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	// 构造数据
	a.NotError(db.Create(&bench{}))
	a.NotError(db.Insert(m))

	for i := 0; i < b.N; i++ {
		a.NotError(db.Where("id=?", i+1).Table("#bench").Update(true, map[string]interface{}{
			"name": "n1",
			"pass": "p1",
			"site": "s1",
		}))
	}
}

// mysql: BenchmarkDB_WhereSelect	   10000	    182159 ns/op
func BenchmarkDB_WhereSelect(b *testing.B) {
	a := assert.New(b)

	ms := make([]interface{}, 0, 100)
	for i := 0; i < cap(ms); i++ {
		ms = append(ms, &bench{
			Name: "name",
			Pass: "<PASSWORD>",
			Site: "http://www.github.com/issue9/orm",
		})
	}

	db := newDB(a)
	defer func() {
		db.Drop(&bench{})
		closeDB(a)
	}()

	// 构造数据
	a.NotError(db.Create(&bench{}))
	a.NotError(db.Insert(ms...))

	models := make([]*bench, 0, 100)
	for i := 0; i < cap(models); i++ {
		models = append(models, &bench{
			Name: "name",
			Pass: "<PASSWORD>",
			Site: "http://www.github.com/issue9/orm",
		})
	}
	for i := 0; i < b.N; i++ {
		a.NotError(db.Where("id>?", i).Table("#bench").Select(true, models))
	}
}

{'fraction_non_alphanumeric': 0.22096430474160894, 'fraction_numerical': 0.03183271177410762, 'mean_word_length': 2.9109375, 'pattern_counts': {'":': 3, '<': 40, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 15, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4780080', 'n_tokens_mistral': 3697, 'n_tokens_neox': 3330, 'n_words': 676}