From fe439d04ec2045ec7b48b622e287d08a0f393e42 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sat, 25 Dec 2021 23:34:22 -0500 Subject: [PATCH] some go-benchmark files for Mac/Linux perf comparisons --- Makefile | 17 +++-- .../pkg/input/record_reader_benchmark_test.go | 71 +++++++++++++++++++ internal/pkg/mlrval/mlrval_benchmark_test.go | 35 +++++++++ scripts/chain-1.mlr | 2 +- todo.txt | 1 + 5 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 internal/pkg/input/record_reader_benchmark_test.go create mode 100644 internal/pkg/mlrval/mlrval_benchmark_test.go diff --git a/Makefile b/Makefile index 4af0cc6f7..39270b578 100644 --- a/Makefile +++ b/Makefile @@ -31,15 +31,22 @@ install: build unit-test ut: go test github.com/johnkerl/miller/internal/pkg/... -lib-ut: +ut-lib: go test github.com/johnkerl/miller/internal/pkg/lib... -mv-ut: +ut-mlv: go test github.com/johnkerl/miller/internal/pkg/mlrval/... -bifs-ut: +ut-bifs: go test github.com/johnkerl/miller/internal/pkg/bifs/... -input-ut: +ut-input: go test github.com/johnkerl/miller/internal/pkg/input/... +bench: + go test -run=nonesuch -bench=. github.com/johnkerl/miller/internal/pkg/... +bench-mlv: + go test -run=nonesuch -bench=. github.com/johnkerl/miller/internal/pkg/mlrval/... +bench-input: + go test -run=nonesuch -bench=. github.com/johnkerl/miller/internal/pkg/input/... + # ---------------------------------------------------------------- # Regression tests (large number) # @@ -102,4 +109,4 @@ release_tarball: build check # ================================================================ # Go does its own dependency management, outside of make. -.PHONY: build mlr check unit_test regression_test fmt staticcheck dev docs +.PHONY: build mlr check unit_test regression_test bench fmt staticcheck dev docs diff --git a/internal/pkg/input/record_reader_benchmark_test.go b/internal/pkg/input/record_reader_benchmark_test.go new file mode 100644 index 000000000..93ce89857 --- /dev/null +++ b/internal/pkg/input/record_reader_benchmark_test.go @@ -0,0 +1,71 @@ +package input + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/johnkerl/miller/internal/pkg/cli" +) + +// go test -run=nonesuch -bench=. github.com/johnkerl/miller/internal/pkg/input/... + +func BenchmarkDKVPParse(b *testing.B) { + readerOptions := &cli.TReaderOptions{ + InputFileFormat: "dkvp", + IFS: ",", + IPS: "=", + IRS: "\n", + } + reader, err := NewRecordReaderDKVP(readerOptions, 1) + assert.Nil(b, err) + + for i := 0; i < b.N; i++ { + _, _ = recordFromDKVPLine( + reader, + "color=yellow,shape=triangle,flag=true,k=1,index=11,quantity=43.6498,rate=9.8870", + ) + } +} + +func BenchmarkNIDXParse(b *testing.B) { + readerOptions := &cli.TReaderOptions{ + InputFileFormat: "nidx", + IFS: " ", + AllowRepeatIFS: true, + IRS: "\n", + } + reader, err := NewRecordReaderNIDX(readerOptions, 1) + assert.Nil(b, err) + + for i := 0; i < b.N; i++ { + _, _ = recordFromDKVPLine( + reader, + "yellow triangle true 1 11 43.6498 9.8870", + ) + } +} + +func BenchmarkXTABParse(b *testing.B) { + readerOptions := &cli.TReaderOptions{ + InputFileFormat: "xtab", + IPS: " ", + IFS: "\n", + IRS: "\n", + } + reader, err := NewRecordReaderXTAB(readerOptions, 1) + assert.Nil(b, err) + + stanza := newStanza() + stanza.dataLines.PushBack("color yellow") + stanza.dataLines.PushBack("shape triangle") + stanza.dataLines.PushBack("flag true") + stanza.dataLines.PushBack("k 1") + stanza.dataLines.PushBack("index 11") + stanza.dataLines.PushBack("quantity 43.6498") + stanza.dataLines.PushBack("rate 9.8870") + + for i := 0; i < b.N; i++ { + _, _ = reader.recordFromXTABLines(stanza.dataLines) + } +} diff --git a/internal/pkg/mlrval/mlrval_benchmark_test.go b/internal/pkg/mlrval/mlrval_benchmark_test.go new file mode 100644 index 000000000..141e855db --- /dev/null +++ b/internal/pkg/mlrval/mlrval_benchmark_test.go @@ -0,0 +1,35 @@ +package mlrval + +import ( + "testing" +) + +// go test -run=nonesuch -bench=. github.com/johnkerl/miller/internal/pkg/mlrval/... + +func BenchmarkFromDeferredType(b *testing.B) { + for i := 0; i < b.N; i++ { + _ = FromDeferredType("123") + } +} + +func BenchmarkInferIntFromDeferredType(b *testing.B) { + for i := 0; i < b.N; i++ { + mv := FromDeferredType("123") + mv.Type() + } +} + +func BenchmarkInferFloatFromDeferredType(b *testing.B) { + for i := 0; i < b.N; i++ { + mv := FromDeferredType("123.4") + mv.Type() + } +} + +func BenchmarkInferStringFromDeferredType(b *testing.B) { + for i := 0; i < b.N; i++ { + mv := FromDeferredType("abc") + mv.Type() + } +} + diff --git a/scripts/chain-1.mlr b/scripts/chain-1.mlr index c2279799b..05fa01114 100644 --- a/scripts/chain-1.mlr +++ b/scripts/chain-1.mlr @@ -1,2 +1,2 @@ $color_shape = $color . $shape; -$y = int($k) + int($index) **3 + log10(float($quantity)/float($rate)); +$y = $k + $index **3 + log10($quantity/$rate); diff --git a/todo.txt b/todo.txt index 7a4d960a6..672dfbd1b 100644 --- a/todo.txt +++ b/todo.txt @@ -14,6 +14,7 @@ PUNCHDOWN LIST ? array/map fields: marshal as JSON_SINGLE_LINE * numeric-inference perf + o README-profiling.md re various scripts o https://stackoverflow.com/questions/64513411/why-is-strconv-parseuint-so-slow-compared-to-strconv-atoi o benchmark per se o reconsider TryInt/TryFloat -> maybe try number -- ?