Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Add update_time timestamptz to row tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackc committed Jul 14, 2014
1 parent 3ddd2be commit bec0e01
Show file tree
Hide file tree
Showing 3 changed files with 10,024 additions and 10,019 deletions.
34 changes: 19 additions & 15 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ var (

var selectPersonNameSQL = `select first_name from person where id=$1`
var selectPersonSQL = `
select id, first_name, last_name, sex, birth_date, weight, height
select id, first_name, last_name, sex, birth_date, weight, height, update_time
from person
where id=$1`
var selectMultiplePeopleSQL = `
select id, first_name, last_name, sex, birth_date, weight, height
select id, first_name, last_name, sex, birth_date, weight, height, update_time
from person
where id between $1 and $1 + 24`

Expand All @@ -35,13 +35,14 @@ var rawSelectMultiplePeopleStmt *raw.PreparedStatement
var rxBuf []byte

type person struct {
id int32
firstName string
lastName string
sex string
birthDate time.Time
weight int32
height int32
id int32
firstName string
lastName string
sex string
birthDate time.Time
weight int32
height int32
updateTime time.Time
}

func setup(b *testing.B) {
Expand Down Expand Up @@ -256,7 +257,7 @@ func benchmarkPgxNativeSelectSingleRow(b *testing.B, sql string) {

rows, _ := pgxPool.Query("selectPerson", id)
for rows.Next() {
rows.Scan(&p.id, &p.firstName, &p.lastName, &p.sex, &p.birthDate, &p.weight, &p.height)
rows.Scan(&p.id, &p.firstName, &p.lastName, &p.sex, &p.birthDate, &p.weight, &p.height, &p.updateTime)
}
if rows.Err() != nil {
b.Fatalf("pgxPool.Query failed: %v", rows.Err())
Expand Down Expand Up @@ -289,6 +290,9 @@ func checkPersonWasFilled(b *testing.B, p person) {
if p.height == 0 {
b.Fatal("height was 0")
}
if p.updateTime == zeroTime {
b.Fatal("updateTime was zero time")
}
}

func BenchmarkPgxStdlibSelectSingleRowUnprepared(b *testing.B) {
Expand All @@ -308,7 +312,7 @@ func benchmarkSelectSingleRowUnprepared(b *testing.B, db *sql.DB) {
id := randPersonIDs[i%len(randPersonIDs)]
row := db.QueryRow(selectPersonSQL, id)
var p person
err := row.Scan(&p.id, &p.firstName, &p.lastName, &p.sex, &p.birthDate, &p.weight, &p.height)
err := row.Scan(&p.id, &p.firstName, &p.lastName, &p.sex, &p.birthDate, &p.weight, &p.height, &p.updateTime)
if err != nil {
b.Fatalf("row.Scan failed: %v", err)
}
Expand Down Expand Up @@ -352,7 +356,7 @@ func benchmarkSelectSingleRowPrepared(b *testing.B, stmt *sql.Stmt) {
id := randPersonIDs[i%len(randPersonIDs)]
row := stmt.QueryRow(id)
var p person
err := row.Scan(&p.id, &p.firstName, &p.lastName, &p.sex, &p.birthDate, &p.weight, &p.height)
err := row.Scan(&p.id, &p.firstName, &p.lastName, &p.sex, &p.birthDate, &p.weight, &p.height, &p.updateTime)
if err != nil {
b.Fatalf("row.Scan failed: %v", err)
}
Expand Down Expand Up @@ -399,7 +403,7 @@ func benchmarkPgxNativeSelectMultipleRows(b *testing.B, sql string) {
rows, _ := pgxPool.Query(sql, id)
for rows.Next() {
var p person
rows.Scan(&p.id, &p.firstName, &p.lastName, &p.sex, &p.birthDate, &p.weight, &p.height)
rows.Scan(&p.id, &p.firstName, &p.lastName, &p.sex, &p.birthDate, &p.weight, &p.height, &p.updateTime)
people = append(people, p)
}
if rows.Err() != nil {
Expand Down Expand Up @@ -435,7 +439,7 @@ func benchmarkSelectMultipleRowsUnprepared(b *testing.B, db *sql.DB) {

for rows.Next() {
var p person
err := rows.Scan(&p.id, &p.firstName, &p.lastName, &p.sex, &p.birthDate, &p.weight, &p.height)
err := rows.Scan(&p.id, &p.firstName, &p.lastName, &p.sex, &p.birthDate, &p.weight, &p.height, &p.updateTime)
if err != nil {
b.Fatalf("rows.Scan failed: %v", err)
}
Expand Down Expand Up @@ -492,7 +496,7 @@ func benchmarkSelectMultipleRowsPrepared(b *testing.B, stmt *sql.Stmt) {

for rows.Next() {
var p person
err := rows.Scan(&p.id, &p.firstName, &p.lastName, &p.sex, &p.birthDate, &p.weight, &p.height)
err := rows.Scan(&p.id, &p.firstName, &p.lastName, &p.sex, &p.birthDate, &p.weight, &p.height, &p.updateTime)
if err != nil {
b.Fatalf("rows.Scan failed: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions person.sql.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- erb -r ffaker -r date person.sql.erb
insert into person(first_name, last_name, sex, birth_date, weight, height) values
<% 10_000.times do |n| %><%= "," unless n==0 %>('<%= Faker::Name.first_name.gsub("'", "''") %>', '<%= Faker::Name.last_name.gsub("'", "''") %>', '<%= %w[male female].sample %>', '<%= Date.today - rand(10_000) %>', <%= 5 + rand(400) %>, <%= 20 + rand(60) %>)
insert into person(first_name, last_name, sex, birth_date, weight, height, update_time) values
<% 10_000.times do |n| %><%= "," unless n==0 %>('<%= Faker::Name.first_name.gsub("'", "''") %>', '<%= Faker::Name.last_name.gsub("'", "''") %>', '<%= %w[male female].sample %>', '<%= Date.today - rand(10_000) %>', <%= 5 + rand(400) %>, <%= 20 + rand(60) %>, '<%= (Time.now - rand(1_000_000_000)).strftime("%Y-%m-%d %H:%M:%S") %>')
<% end %>;
Loading

0 comments on commit bec0e01

Please sign in to comment.