Add benchmark tests
This commit is contained in:
parent
7f91344fda
commit
fb08c2374e
@ -9,6 +9,10 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
readData()
|
||||
}
|
||||
|
||||
func readData() {
|
||||
f, err := os.Open(common.FileName)
|
||||
if err != nil {
|
||||
fmt.Printf("Error opening input file: %v\n", err)
|
||||
|
||||
9
src/cmd/jsondebug/arrayread/read_test.go
Normal file
9
src/cmd/jsondebug/arrayread/read_test.go
Normal file
@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func Benchmark_readData(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
readData()
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,10 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
readData()
|
||||
}
|
||||
|
||||
func readData() {
|
||||
f, err := os.Open(common.FileName)
|
||||
if err != nil {
|
||||
fmt.Printf("Error opening input file: %v\n", err)
|
||||
|
||||
9
src/cmd/jsondebug/goread/read_test.go
Normal file
9
src/cmd/jsondebug/goread/read_test.go
Normal file
@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func Benchmark_readData(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
readData()
|
||||
}
|
||||
}
|
||||
@ -29,13 +29,26 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
d, err := readFile()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
parseData(d)
|
||||
}
|
||||
|
||||
func readFile() ([]byte, error) {
|
||||
common.PrintMemUsage()
|
||||
|
||||
data, err := ioutil.ReadFile(common.FileName)
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading file: %v\n", err)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func parseData(data []byte) {
|
||||
|
||||
common.PrintMemUsage()
|
||||
|
||||
|
||||
14
src/cmd/jsondebug/jsonparser/read_test.go
Normal file
14
src/cmd/jsondebug/jsonparser/read_test.go
Normal file
@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func Benchmark_parseData(b *testing.B) {
|
||||
d, err := readFile()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
parseData(d)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user