This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmark_insert_1-4 637 1996446 ns/op 7155 B/op 171 allocs/op | |
Benchmark_insert_10-4 403 3375597 ns/op 60062 B/op 1862 allocs/op | |
Benchmark_insert_100-4 46 25023146 ns/op 2944130 B/op 117100 allocs/op | |
Benchmark_insert_1000-4 1 1544852600 ns/op 260334552 B/op 11072318 allocs/op | |
Benchmark_splitInsert_1-4 594 1812986 ns/op 7148 B/op 171 allocs/op | |
Benchmark_splitInsert_10-4 441 2625726 ns/op 60024 B/op 1861 allocs/op | |
Benchmark_splitInsert_100-4 49 22577567 ns/op 2943919 B/op 117099 allocs/op | |
Benchmark_splitInsert_1000-4 5 243017580 ns/op 29459081 B/op 1170782 allocs/op | |
Benchmark_splitInsert_10000-4 1 2398265900 ns/op 294224288 B/op 11707072 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type config struct { | |
returningColumns []string | |
onConflict string | |
} | |
type Option func(*config) | |
func Returning(columns ...string) Option { | |
return func(c *config) { | |
c.returningColumns = columns |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
engine, err := xorm.NewEngine("postgres", "postgres://user:password@db/database?sslmode=disable") | |
if err != nil { | |
log.Println(err) | |
return | |
} | |
defer engine.Close() | |
engine.ShowSQL(true) | |
engine.SetMapper(core.GonicMapper{}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func bulkInsert(db xorm.Interface, us users) error { | |
_, err := BulkInsert(db, us) | |
return err | |
} | |
func Benchmark_bulkInsert_1(b *testing.B) { | |
base(b, 1, bulkInsert) | |
} | |
func Benchmark_bulkInsert_10(b *testing.B) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type bulkInserter interface { | |
TableName() string | |
Args(int) []interface{} | |
Columns() string | |
Values() string | |
Len() int | |
} | |
const pqArgLimit = 65535 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Benchmark_splitInsert_1(b *testing.B) { | |
base(b, 1, splitInsert) | |
} | |
func Benchmark_splitInsert_10(b *testing.B) { | |
base(b, 10, splitInsert) | |
} | |
func Benchmark_splitInsert_100(b *testing.B) { | |
base(b, 100, splitInsert) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func splitInsert(db xorm.Interface, us users) error { | |
const limit = 100 | |
for start := 0; start < us.Len(); start += limit { | |
end := start + limit | |
if end > us.Len() { | |
end = us.Len() | |
} | |
target := us[start:end] | |
_, err := db.Insert(&target) | |
if err != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"testing" | |
"xorm.io/core" | |
"xorm.io/xorm" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"time" | |
_ "github.com/lib/pq" | |
"xorm.io/core" | |
"xorm.io/xorm" |