diff --git a/benchresultsMinMax_Improvement.txt b/benchresultsMinMax_Improvement.txt new file mode 100644 index 0000000..6c53df8 --- /dev/null +++ b/benchresultsMinMax_Improvement.txt @@ -0,0 +1,7 @@ +goos: linux +goarch: amd64 +pkg: github.com/Serares/coolStats +cpu: 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz +BenchmarkRun-16 10 134744628 ns/op +PASS +ok github.com/Serares/coolStats 1.487s diff --git a/cpu01max.pprof b/cpu01max.pprof new file mode 100644 index 0000000..9205e72 Binary files /dev/null and b/cpu01max.pprof differ diff --git a/main.go b/main.go index 2c51ae6..0f36a47 100644 --- a/main.go +++ b/main.go @@ -95,7 +95,33 @@ func run(filenames []string, op string, column int, out io.Writer) error { return err case data := <-resCh: if op == "min" || op == "max" { - consolidate = append(consolidate, opFunc(data)) + // todo see if using goroutines here can improve the performance + // spawn like 4 goroutines and divide the date between them to be processed + minWg := sync.WaitGroup{} + theData := make(chan float64) + quarterLength := len(data) / 4 + start := 0 + endQuarter := quarterLength + incrementQuarter := 2 + for i := 0; i < 4; i++ { + minWg.Add(1) + go func(start, end int) { + defer minWg.Done() + theData <- opFunc(data[start:end]) + }(start, endQuarter) + start = endQuarter + endQuarter = quarterLength * incrementQuarter + incrementQuarter++ + } + go func() { + minWg.Wait() + close(theData) + }() + + for quarterData := range theData { + consolidate = append(consolidate, quarterData) + } + } else { consolidate = append(consolidate, data...) }