From 01b127b095ee7093ff75545b1dace75ea3e32518 Mon Sep 17 00:00:00 2001 From: Hikmatulloh Hari Mukti Date: Mon, 8 Apr 2024 15:38:42 +0700 Subject: [PATCH] chore: update internal/cmd/benchfit and README.md --- README.md | 15 +++++++-------- internal/cmd/benchfit/benchfit_test.go | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 3fe5bdcf..a78ddc1a 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/internal/cmd/benchfit/benchfit_test.go b/internal/cmd/benchfit/benchfit_test.go index 971831a5..e6ff0371 100644 --- a/internal/cmd/benchfit/benchfit_test.go +++ b/internal/cmd/benchfit/benchfit_test.go @@ -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) @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 {