From 4f30a593ea6c267666d4389093db89063b6e1913 Mon Sep 17 00:00:00 2001 From: "Dr. Carsten Leue" Date: Fri, 27 Oct 2023 13:23:21 +0200 Subject: [PATCH] fix: benchmarks Signed-off-by: Dr. Carsten Leue --- samples/presentation/benchmarks/http_test.go | 7 +++-- samples/presentation/benchmarks/map_test.go | 27 ++++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/samples/presentation/benchmarks/http_test.go b/samples/presentation/benchmarks/http_test.go index 390a0cc..53d55de 100644 --- a/samples/presentation/benchmarks/http_test.go +++ b/samples/presentation/benchmarks/http_test.go @@ -105,16 +105,19 @@ func heterogeneousHttpRequestsIdiomatic(count int) ([]T.Tuple2[PostItem, CatFact func BenchmarkHeterogeneousHttpRequests(b *testing.B) { count := 100 + var benchResults any b.Run("functional", func(b *testing.B) { for n := 0; n < b.N; n++ { - heterogeneousHttpRequests(count)(context.Background())() + benchResults = heterogeneousHttpRequests(count)(context.Background())() } }) b.Run("idiomatic", func(b *testing.B) { for n := 0; n < b.N; n++ { - heterogeneousHttpRequestsIdiomatic(count) + benchResults, _ = heterogeneousHttpRequestsIdiomatic(count) } }) + + globalResult = benchResults } diff --git a/samples/presentation/benchmarks/map_test.go b/samples/presentation/benchmarks/map_test.go index 7a83fea..4931d23 100644 --- a/samples/presentation/benchmarks/map_test.go +++ b/samples/presentation/benchmarks/map_test.go @@ -29,15 +29,19 @@ import ( var ( createStringSet = createRandom(createRandomString(256))(256) createIntDataSet = createRandom(randInt(10000))(256) + + globalResult any ) func BenchmarkMap(b *testing.B) { data := createStringSet() + var benchResult []string + b.Run("functional", func(b *testing.B) { for n := 0; n < b.N; n++ { - F.Pipe1( + benchResult = F.Pipe1( data, A.Map(strings.ToUpper), ) @@ -50,8 +54,11 @@ func BenchmarkMap(b *testing.B) { for _, value := range data { result = append(result, strings.ToUpper(value)) } + benchResult = result } }) + + globalResult = benchResult } func isEven(data int) bool { @@ -65,10 +72,11 @@ func isPrime(data int) bool { func BenchmarkMapThenFilter(b *testing.B) { data := createIntDataSet() + var benchResult []int b.Run("functional isPrime", func(b *testing.B) { for n := 0; n < b.N; n++ { - F.Pipe2( + benchResult = F.Pipe2( data, A.Filter(isPrime), A.Map(N.Div[int](2)), @@ -84,11 +92,12 @@ func BenchmarkMapThenFilter(b *testing.B) { result = append(result, value/2) } } + benchResult = result } }) b.Run("functional isEven", func(b *testing.B) { for n := 0; n < b.N; n++ { - F.Pipe2( + benchResult = F.Pipe2( data, A.Filter(isEven), A.Map(N.Div[int](2)), @@ -104,17 +113,21 @@ func BenchmarkMapThenFilter(b *testing.B) { result = append(result, value/2) } } + benchResult = result } }) + + globalResult = benchResult } func BenchmarkFilterMap(b *testing.B) { data := createIntDataSet() + var benchResult []int b.Run("functional isPrime", func(b *testing.B) { for n := 0; n < b.N; n++ { - F.Pipe1( + benchResult = F.Pipe1( data, A.FilterMap(F.Flow2( O.FromPredicate(isPrime), @@ -132,12 +145,13 @@ func BenchmarkFilterMap(b *testing.B) { result = append(result, value/2) } } + benchResult = result } }) b.Run("functional isEven", func(b *testing.B) { for n := 0; n < b.N; n++ { - F.Pipe1( + benchResult = F.Pipe1( data, A.FilterMap(F.Flow2( O.FromPredicate(isEven), @@ -155,6 +169,9 @@ func BenchmarkFilterMap(b *testing.B) { result = append(result, value/2) } } + benchResult = result } }) + + globalResult = benchResult }