-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ianlopshire/feature/encoding-performance
Encoding Performance Improvements
- Loading branch information
Showing
3 changed files
with
212 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
package fixedwidth | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
type mixedData struct { | ||
F1 string `fixed:"1,10"` | ||
F2 *string `fixed:"11,20"` | ||
F3 int64 `fixed:"21,30"` | ||
F4 *int64 `fixed:"31,40"` | ||
F5 int32 `fixed:"41,50"` | ||
F6 *int32 `fixed:"51,60"` | ||
F7 int16 `fixed:"61,70"` | ||
F8 *int16 `fixed:"71,80"` | ||
F9 int8 `fixed:"81,90"` | ||
F10 *int8 `fixed:"91,100"` | ||
F11 float64 `fixed:"101,110"` | ||
F12 *float64 `fixed:"111,120"` | ||
F13 float32 `fixed:"121,130"` | ||
//F14 *float32 `fixed:"131,140"` | ||
} | ||
|
||
var mixedDataInstance = mixedData{"foo", stringp("foo"), 42, int64p(42), 42, int32p(42), 42, int16p(42), 42, int8p(42), 4.2, float64p(4.2), 4.2} //,float32p(4.2)} | ||
|
||
func BenchmarkUnmarshal_MixedData_1(b *testing.B) { | ||
data := []byte(` foo foo 42 42 42 42 42 42 42 42 4.2 4.2 4.2 4.2`) | ||
var v mixedData | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = Unmarshal(data, &v) | ||
} | ||
} | ||
|
||
func BenchmarkUnmarshal_MixedData_1000(b *testing.B) { | ||
data := bytes.Repeat([]byte(` foo foo 42 42 42 42 42 42 42 42 4.2 4.2 4.2 4.2`+"\n"), 100) | ||
var v []mixedData | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = Unmarshal(data, &v) | ||
} | ||
} | ||
|
||
func BenchmarkUnmarshal_MixedData_100000(b *testing.B) { | ||
data := bytes.Repeat([]byte(` foo foo 42 42 42 42 42 42 42 42 4.2 4.2 4.2 4.2`+"\n"), 10000) | ||
var v []mixedData | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = Unmarshal(data, &v) | ||
} | ||
} | ||
|
||
func BenchmarkUnmarshal_String(b *testing.B) { | ||
data := []byte(`foo `) | ||
var v struct { | ||
F1 string `fixed:"1,10"` | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = Unmarshal(data, &v) | ||
} | ||
} | ||
|
||
func BenchmarkUnmarshal_StringPtr(b *testing.B) { | ||
data := []byte(`foo `) | ||
var v struct { | ||
F1 *string `fixed:"1,10"` | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = Unmarshal(data, &v) | ||
} | ||
} | ||
|
||
func BenchmarkUnmarshal_Int64(b *testing.B) { | ||
data := []byte(`42 `) | ||
var v struct { | ||
F1 int64 `fixed:"1,10"` | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = Unmarshal(data, &v) | ||
} | ||
} | ||
|
||
func BenchmarkUnmarshal_Float64(b *testing.B) { | ||
data := []byte(`4.2 `) | ||
var v struct { | ||
F1 float64 `fixed:"1,10"` | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = Unmarshal(data, &v) | ||
} | ||
} | ||
|
||
func BenchmarkMarshal_MixedData_1(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
Marshal(mixedDataInstance) | ||
} | ||
} | ||
|
||
func BenchmarkMarshal_MixedData_1000(b *testing.B) { | ||
v := make([]mixedData, 1000) | ||
for i := range v { | ||
v[i] = mixedDataInstance | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
Marshal(v) | ||
} | ||
} | ||
|
||
func BenchmarkMarshal_MixedData_100000(b *testing.B) { | ||
v := make([]mixedData, 100000) | ||
for i := range v { | ||
v[i] = mixedDataInstance | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
Marshal(v) | ||
} | ||
} | ||
|
||
func BenchmarkMarshal_String(b *testing.B) { | ||
v := struct { | ||
F1 string `fixed:"1,10"` | ||
}{ | ||
F1: "foo", | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
Marshal(v) | ||
} | ||
} | ||
|
||
func BenchmarkMarshal_StringPtr(b *testing.B) { | ||
v := struct { | ||
F1 *string `fixed:"1,10"` | ||
}{ | ||
F1: stringp("foo"), | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
Marshal(v) | ||
} | ||
} | ||
|
||
func BenchmarkMarshal_Int64(b *testing.B) { | ||
v := struct { | ||
F1 int64 `fixed:"1,10"` | ||
}{ | ||
F1: 42, | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
Marshal(v) | ||
} | ||
} | ||
|
||
func BenchmarkMarshal_Float64(b *testing.B) { | ||
v := struct { | ||
F1 float64 `fixed:"1,10"` | ||
}{ | ||
F1: 4.2, | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
Marshal(v) | ||
} | ||
} |
This file contains 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
This file contains 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