Skip to content

Commit

Permalink
add ajg benchmarks as someone requested a comparrison
Browse files Browse the repository at this point in the history
  • Loading branch information
joeybloggs authored and joeybloggs committed Jun 23, 2016
1 parent 16f5e63 commit cbd857f
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 77 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package form
============
<img align="right" src="https://raw.githubusercontent.com/go-playground/form/master/logo.jpg">
![Project status](https://img.shields.io/badge/version-1.5.0-green.svg)
![Project status](https://img.shields.io/badge/version-1.6.0-green.svg)
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/form/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/form)
[![Coverage Status](https://coveralls.io/repos/github/go-playground/form/badge.svg?branch=master)](https://coveralls.io/github/go-playground/form?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/form)](https://goreportcard.com/report/github.com/go-playground/form)
Expand Down
305 changes: 305 additions & 0 deletions benchmarks/ajg_form_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
package benchmarks

import (
"net/url"
"testing"

ajg "github.com/ajg/form"
)

// Simple Benchmarks

func BenchmarkSimpleUserDecodeStructAGJForm(b *testing.B) {

values := getUserStructValues()

b.ReportAllocs()
for n := 0; n < b.N; n++ {
var test User
if err := ajg.DecodeValues(&test, values); err != nil {
b.Error(err)
}
}
}

func BenchmarkSimpleUserDecodeStructParallelAGJFrom(b *testing.B) {

values := getUserStructValues()

b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
var test User
if err := ajg.DecodeValues(&test, values); err != nil {
b.Error(err)
}
}
})
}

func BenchmarkSimpleUserEncodeStructAGJForm(b *testing.B) {

test := getUserStruct()

b.ReportAllocs()
for n := 0; n < b.N; n++ {
if _, err := ajg.EncodeToValues(&test); err != nil {
b.Error(err)
}
}
}

func BenchmarkSimpleUserEncodeStructParallelAGJForm(b *testing.B) {

test := getUserStruct()

b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
if _, err := ajg.EncodeToValues(&test); err != nil {
b.Error(err)
}
}
})
}

// Primitives ALL types

func BenchmarkPrimitivesDecodeStructAllPrimitivesTypesAGJForm(b *testing.B) {
values := getPrimitivesStructValues()

b.ReportAllocs()
for n := 0; n < b.N; n++ {
var test PrimitivesStruct
if err := ajg.DecodeValues(&test, values); err != nil {
b.Error(err)
}
}
}

func BenchmarkPrimitivesDecodeStructAllPrimitivesTypesParallelAGJForm(b *testing.B) {
values := getPrimitivesStructValues()

b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
var test PrimitivesStruct
if err := ajg.DecodeValues(&test, values); err != nil {
b.Error(err)
}
}
})
}

func BenchmarkPrimitivesEncodeStructAllPrimitivesTypesAGJForm(b *testing.B) {
test := getPrimitivesStruct()

b.ReportAllocs()
for n := 0; n < b.N; n++ {
if _, err := ajg.EncodeToValues(&test); err != nil {
b.Error(err)
}
}
}

func BenchmarkPrimitivesEncodeStructAllPrimitivesTypesParallelAGJForm(b *testing.B) {
test := getPrimitivesStruct()

b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
if _, err := ajg.EncodeToValues(&test); err != nil {
b.Error(err)
}
}
})
}

// Complex Array ALL types

func BenchmarkComplexArrayDecodeStructAllTypesAGJForm(b *testing.B) {
values := getComplexArrayStructValues()

b.ReportAllocs()
for n := 0; n < b.N; n++ {
var test ComplexArrayStruct
if err := ajg.DecodeValues(&test, values); err != nil {
b.Error(err)
}
}
}

func BenchmarkComplexArrayDecodeStructAllTypesParallelAGJForm(b *testing.B) {
values := getComplexArrayStructValues()

b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
var test ComplexArrayStruct
if err := ajg.DecodeValues(&test, values); err != nil {
b.Error(err)
}
}
})
}

func BenchmarkComplexArrayEncodeStructAllTypesAGJForm(b *testing.B) {
test := getComplexArrayStruct()

b.ReportAllocs()
for n := 0; n < b.N; n++ {
if _, err := ajg.EncodeToValues(&test); err != nil {
b.Error(err)
}
}
}

func BenchmarkComplexArrayEncodeStructAllTypesParallelAGJForm(b *testing.B) {
test := getComplexArrayStruct()

b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
if _, err := ajg.EncodeToValues(&test); err != nil {
b.Error(err)
}
}
})
}

// Complex Map ALL types

func getComplexMapStructValuesAGJForm() url.Values {
return url.Values{
"String.key": []string{"value"},
"StringPtr.key": []string{"value"},
"Int.0": []string{"1"},
"IntPtr.0": []string{"1"},
"Int8.0": []string{"1"},
"Int8Ptr.0": []string{"1"},
"Int16.0": []string{"1"},
"Int16Ptr.0": []string{"1"},
"Int32.0": []string{"1"},
"Int32Ptr.0": []string{"1"},
"Int64.0": []string{"1"},
"Int64Ptr.0": []string{"1"},
"Uint.0": []string{"1"},
"UintPtr.0": []string{"1"},
"Uint8.0": []string{"1"},
"Uint8Ptr.0": []string{"1"},
"Uint16.0": []string{"1"},
"Uint16Ptr.0": []string{"1"},
"Uint32.0": []string{"1"},
"Uint32Ptr.0": []string{"1"},
"Uint64.0": []string{"1"},
"Uint64Ptr.0": []string{"1"},
"NestedInt.1.2": []string{"3"},
"NestedIntPtr.1.2": []string{"3"},
}
}

func BenchmarkComplexMapDecodeStructAllTypesAGJForm(b *testing.B) {
values := getComplexMapStructValuesAGJForm()

b.ReportAllocs()
for n := 0; n < b.N; n++ {
var test ComplexMapStruct
if err := ajg.DecodeValues(&test, values); err != nil {
b.Error(err)
}
}
}

func BenchmarkComplexMapDecodeStructAllTypesParallelAGJForm(b *testing.B) {
values := getComplexMapStructValuesAGJForm()

b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
var test ComplexMapStruct
if err := ajg.DecodeValues(&test, values); err != nil {
b.Error(err)
}
}
})
}

func BenchmarkComplexMapEncodeStructAllTypesAGJForm(b *testing.B) {
test := getComplexMapStructValuesAGJForm()

b.ReportAllocs()
for n := 0; n < b.N; n++ {
if _, err := ajg.EncodeToValues(&test); err != nil {
b.Error(err)
}
}
}

func BenchmarkComplexMapEncodeStructAllTypesParallelAGJForm(b *testing.B) {
test := getComplexMapStructValuesAGJForm()

b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
if _, err := ajg.EncodeToValues(&test); err != nil {
b.Error(err)
}
}
})
}

// NestedStruct Benchmarks

func BenchmarkDecodeNestedStructAGJForm(b *testing.B) {

values := getNestedStructValues()

b.ReportAllocs()
for n := 0; n < b.N; n++ {
var test NestedStruct
if err := ajg.DecodeValues(&test, values); err != nil {
b.Error(err)
}
}
}

func BenchmarkDecodeNestedStructParallelAGJForm(b *testing.B) {

values := getNestedStructValues()

b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
var test NestedStruct
if err := ajg.DecodeValues(&test, values); err != nil {
b.Error(err)
}
}
})
}

func BenchmarkEncodeNestedStructAGJForm(b *testing.B) {

test := getNestedStruct()

b.ReportAllocs()
for n := 0; n < b.N; n++ {
if _, err := ajg.EncodeToValues(&test); err != nil {
b.Error(err)
}
}
}

func BenchmarkEncodeNestedStructParallelAGJForm(b *testing.B) {

test := getNestedStruct()

b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
if _, err := ajg.EncodeToValues(&test); err != nil {
b.Error(err)
}
}
})
}
28 changes: 28 additions & 0 deletions benchmarks/benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,32 @@ BenchmarkArrayMapNestedStructFormam-8 --- FAIL: Benchmark
BenchmarkArrayMapNestedStructFormamParallel-8 --- FAIL: BenchmarkArrayMapNestedStructFormamParallel-8
formam_test.go:189: formam: not supported type for field "Value" in path "NestedPtrArray[0].Value"
No Encoder Support At This Time
```

### ajg/form
```go
BenchmarkSimpleUserDecodeStructAGJForm-8 200000 6104 ns/op 1320 B/op 34 allocs/op
BenchmarkSimpleUserDecodeStructParallelAGJFrom-8 1000000 1748 ns/op 1320 B/op 34 allocs/op
BenchmarkSimpleUserEncodeStructAGJForm-8 300000 5076 ns/op 1272 B/op 29 allocs/op
BenchmarkSimpleUserEncodeStructParallelAGJForm-8 1000000 1440 ns/op 1272 B/op 29 allocs/op
BenchmarkPrimitivesDecodeStructAllPrimitivesTypesAGJForm-8 100000 19713 ns/op 5661 B/op 143 allocs/op
BenchmarkPrimitivesDecodeStructAllPrimitivesTypesParallelAGJForm-8 300000 5618 ns/op 5663 B/op 143 allocs/op
BenchmarkPrimitivesEncodeStructAllPrimitivesTypesAGJForm-8 100000 15097 ns/op 5792 B/op 82 allocs/op
BenchmarkPrimitivesEncodeStructAllPrimitivesTypesParallelAGJForm-8 300000 4340 ns/op 5792 B/op 82 allocs/op
BenchmarkComplexArrayDecodeStructAllTypesAGJForm-8 --- FAIL: BenchmarkComplexArrayDecodeStructAllTypesAGJForm-8
agj_form_test.go:127: is not a valid index for type []uint16
BenchmarkComplexArrayDecodeStructAllTypesParallelAGJForm-8 --- FAIL: BenchmarkComplexArrayDecodeStructAllTypesParallelAGJForm-8
agj_form_test.go:140: is not a valid index for type []int32
BenchmarkComplexArrayEncodeStructAllTypesAGJForm-8 20000 66822 ns/op 21684 B/op 400 allocs/op
BenchmarkComplexArrayEncodeStructAllTypesParallelAGJForm-8 100000 20173 ns/op 21681 B/op 400 allocs/op
BenchmarkComplexMapDecodeStructAllTypesAGJForm-8 20000 86037 ns/op 22295 B/op 592 allocs/op
BenchmarkComplexMapDecodeStructAllTypesParallelAGJForm-8 50000 25491 ns/op 22297 B/op 592 allocs/op
BenchmarkComplexMapEncodeStructAllTypesAGJForm-8 30000 44735 ns/op 17959 B/op 323 allocs/op
BenchmarkComplexMapEncodeStructAllTypesParallelAGJForm-8 100000 13961 ns/op 17958 B/op 323 allocs/op
BenchmarkDecodeNestedStructAGJForm-8 --- FAIL: BenchmarkDecodeNestedStructAGJForm-8
agj_form_test.go:261: NestedArray[1] doesn't exist in benchmarks.NestedStruct
BenchmarkDecodeNestedStructParallelAGJForm-8 --- FAIL: BenchmarkDecodeNestedStructParallelAGJForm-8
agj_form_test.go:275: NestedArray[0] doesn't exist in benchmarks.NestedStruct
BenchmarkEncodeNestedStructAGJForm-8 100000 17904 ns/op 5704 B/op 113 allocs/op
BenchmarkEncodeNestedStructParallelAGJForm-8 300000 5502 ns/op 5704 B/op 113 allocs/op
```
Loading

0 comments on commit cbd857f

Please # to comment.