Skip to content

Commit

Permalink
chore: update internal/cmd/benchfit and README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
muktihari committed Apr 8, 2024
1 parent cb05c27 commit 01b127b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,14 @@ goos: darwin
goarch: amd64
pkg: benchfit
cpu: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
BenchmarkDec/github.com/muktihari/fit_raw-4 10 108122640 ns/op 77077265 B/op 100047 allocs/op
BenchmarkDec/github.com/muktihari/fit-4 9 119712969 ns/op 97035622 B/op 200067 allocs/op
BenchmarkDec/github.com/tormoder/fit-4 10 107630537 ns/op 84108936 B/op 700051 allocs/op
-----------------------------------------------------------------------------------------------------
BenchmarkEnc/github.com/muktihari/fit_raw-4 13 87780351 ns/op 10217 B/op 2 allocs/op
BenchmarkEnc/github.com/muktihari/fit-4 7 151018842 ns/op 44027624 B/op 100007 allocs/op
BenchmarkEnc/github.com/tormoder/fit-4 1 1389844685 ns/op 101592576 B/op 12100312 allocs/op
BenchmarkDecode/muktihari/fit_raw-4 10 110165214 ns/op 77077057 B/op 100047 allocs/op
BenchmarkDecode/muktihari/fit-4 9 121938626 ns/op 97035515 B/op 200066 allocs/op
BenchmarkDecode/tormoder/fit-4 9 112157057 ns/op 84108961 B/op 700051 allocs/op
BenchmarkEncode/muktihari/fit_raw-4 13 87579657 ns/op 12444 B/op 16 allocs/op
BenchmarkEncode/muktihari/fit-4 7 151469391 ns/op 44065838 B/op 100021 allocs/op
BenchmarkEncode/tormoder/fit-4 1 1300131309 ns/op 101992736 B/op 12100314 allocs/op
PASS
ok benchfit 9.004s
ok benchfit 10.811s
```

NOTE: The `1st` on the list, "raw", means we decode the file into the original FIT protocol message structure (similar to the Official FIT SDK implementation in other languages). While the `2nd` decodes messages to **Activity File** struct, which should be equivalent to what the `3rd` does.
Expand Down
20 changes: 10 additions & 10 deletions internal/cmd/benchfit/benchfit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ var (
big_activity = filepath.Join(testdata, "big_activity.fit")
)

func BenchmarkDec(b *testing.B) {
b.Run("github.com/muktihari/fit raw", func(b *testing.B) {
func BenchmarkDecode(b *testing.B) {
b.Run("muktihari/fit raw", func(b *testing.B) {
b.StopTimer()
// NOTE: We use os.ReadFile to remove syscall process in our decoding process. So we have pure decoding performance.
f, err := os.ReadFile(big_activity)
Expand All @@ -42,7 +42,7 @@ func BenchmarkDec(b *testing.B) {
}
}
})
b.Run("github.com/muktihari/fit", func(b *testing.B) {
b.Run("muktihari/fit", func(b *testing.B) {
b.StopTimer()
f, err := os.ReadFile(big_activity)
if err != nil {
Expand All @@ -64,7 +64,7 @@ func BenchmarkDec(b *testing.B) {
al.Close()
}
})
b.Run("github.com/tormoder/fit", func(b *testing.B) {
b.Run("tormoder/fit", func(b *testing.B) {
b.StopTimer()
f, err := os.ReadFile(big_activity)
if err != nil {
Expand Down Expand Up @@ -92,8 +92,8 @@ func (discardAt) Write(p []byte) (int, error) { return len(p), nil }

func (discardAt) WriteAt(p []byte, off int64) (n int, err error) { return len(p), nil }

func BenchmarkEnc(b *testing.B) {
b.Run("github.com/muktihari/fit raw", func(b *testing.B) {
func BenchmarkEncode(b *testing.B) {
b.Run("muktihari/fit raw", func(b *testing.B) {
b.StopTimer()
f, err := os.ReadFile(big_activity)
if err != nil {
Expand All @@ -107,16 +107,16 @@ func BenchmarkEnc(b *testing.B) {
b.Fatalf("decode error: %v", err)
}

enc := encoder.New(discard)
b.StartTimer()

for i := 0; i < b.N; i++ {
enc := encoder.New(discard) // include the encoder creation.
if err := enc.Encode(fit); err != nil {
b.Fatalf("encode error: %v", err)
}
}
})
b.Run("github.com/muktihari/fit", func(b *testing.B) {
b.Run("muktihari/fit", func(b *testing.B) {
b.StopTimer()
f, err := os.ReadFile(big_activity)
if err != nil {
Expand All @@ -138,17 +138,17 @@ func BenchmarkEnc(b *testing.B) {

activity := al.File().(*filedef.Activity)

enc := encoder.New(discard)
b.StartTimer()

for i := 0; i < b.N; i++ {
fit := activity.ToFIT(nil)
enc := encoder.New(discard)
if err := enc.Encode(&fit); err != nil {
b.Fatalf("encode error: %v", err)
}
}
})
b.Run("github.com/tormoder/fit", func(b *testing.B) {
b.Run("tormoder/fit", func(b *testing.B) {
b.StopTimer()
f, err := os.ReadFile(big_activity)
if err != nil {
Expand Down

0 comments on commit 01b127b

Please sign in to comment.