Add benchmark tests

This commit is contained in:
Vaibhav Kamra 2023-03-31 10:29:40 -07:00
parent 7f91344fda
commit fb08c2374e
6 changed files with 54 additions and 1 deletions

View File

@ -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)

View File

@ -0,0 +1,9 @@
package main
import "testing"
func Benchmark_readData(b *testing.B) {
for i := 0; i < b.N; i++ {
readData()
}
}

View File

@ -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)

View File

@ -0,0 +1,9 @@
package main
import "testing"
func Benchmark_readData(b *testing.B) {
for i := 0; i < b.N; i++ {
readData()
}
}

View File

@ -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()

View 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)
}
}