mirror of
https://github.com/IBM/fp-go.git
synced 2025-11-27 22:28:29 +02:00
fix: benchmarks
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@@ -105,16 +105,19 @@ func heterogeneousHttpRequestsIdiomatic(count int) ([]T.Tuple2[PostItem, CatFact
|
|||||||
func BenchmarkHeterogeneousHttpRequests(b *testing.B) {
|
func BenchmarkHeterogeneousHttpRequests(b *testing.B) {
|
||||||
|
|
||||||
count := 100
|
count := 100
|
||||||
|
var benchResults any
|
||||||
|
|
||||||
b.Run("functional", func(b *testing.B) {
|
b.Run("functional", func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
heterogeneousHttpRequests(count)(context.Background())()
|
benchResults = heterogeneousHttpRequests(count)(context.Background())()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
b.Run("idiomatic", func(b *testing.B) {
|
b.Run("idiomatic", func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
heterogeneousHttpRequestsIdiomatic(count)
|
benchResults, _ = heterogeneousHttpRequestsIdiomatic(count)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
globalResult = benchResults
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,15 +29,19 @@ import (
|
|||||||
var (
|
var (
|
||||||
createStringSet = createRandom(createRandomString(256))(256)
|
createStringSet = createRandom(createRandomString(256))(256)
|
||||||
createIntDataSet = createRandom(randInt(10000))(256)
|
createIntDataSet = createRandom(randInt(10000))(256)
|
||||||
|
|
||||||
|
globalResult any
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkMap(b *testing.B) {
|
func BenchmarkMap(b *testing.B) {
|
||||||
|
|
||||||
data := createStringSet()
|
data := createStringSet()
|
||||||
|
|
||||||
|
var benchResult []string
|
||||||
|
|
||||||
b.Run("functional", func(b *testing.B) {
|
b.Run("functional", func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
F.Pipe1(
|
benchResult = F.Pipe1(
|
||||||
data,
|
data,
|
||||||
A.Map(strings.ToUpper),
|
A.Map(strings.ToUpper),
|
||||||
)
|
)
|
||||||
@@ -50,8 +54,11 @@ func BenchmarkMap(b *testing.B) {
|
|||||||
for _, value := range data {
|
for _, value := range data {
|
||||||
result = append(result, strings.ToUpper(value))
|
result = append(result, strings.ToUpper(value))
|
||||||
}
|
}
|
||||||
|
benchResult = result
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
globalResult = benchResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func isEven(data int) bool {
|
func isEven(data int) bool {
|
||||||
@@ -65,10 +72,11 @@ func isPrime(data int) bool {
|
|||||||
func BenchmarkMapThenFilter(b *testing.B) {
|
func BenchmarkMapThenFilter(b *testing.B) {
|
||||||
|
|
||||||
data := createIntDataSet()
|
data := createIntDataSet()
|
||||||
|
var benchResult []int
|
||||||
|
|
||||||
b.Run("functional isPrime", func(b *testing.B) {
|
b.Run("functional isPrime", func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
F.Pipe2(
|
benchResult = F.Pipe2(
|
||||||
data,
|
data,
|
||||||
A.Filter(isPrime),
|
A.Filter(isPrime),
|
||||||
A.Map(N.Div[int](2)),
|
A.Map(N.Div[int](2)),
|
||||||
@@ -84,11 +92,12 @@ func BenchmarkMapThenFilter(b *testing.B) {
|
|||||||
result = append(result, value/2)
|
result = append(result, value/2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
benchResult = result
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
b.Run("functional isEven", func(b *testing.B) {
|
b.Run("functional isEven", func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
F.Pipe2(
|
benchResult = F.Pipe2(
|
||||||
data,
|
data,
|
||||||
A.Filter(isEven),
|
A.Filter(isEven),
|
||||||
A.Map(N.Div[int](2)),
|
A.Map(N.Div[int](2)),
|
||||||
@@ -104,17 +113,21 @@ func BenchmarkMapThenFilter(b *testing.B) {
|
|||||||
result = append(result, value/2)
|
result = append(result, value/2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
benchResult = result
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
globalResult = benchResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkFilterMap(b *testing.B) {
|
func BenchmarkFilterMap(b *testing.B) {
|
||||||
|
|
||||||
data := createIntDataSet()
|
data := createIntDataSet()
|
||||||
|
var benchResult []int
|
||||||
|
|
||||||
b.Run("functional isPrime", func(b *testing.B) {
|
b.Run("functional isPrime", func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
F.Pipe1(
|
benchResult = F.Pipe1(
|
||||||
data,
|
data,
|
||||||
A.FilterMap(F.Flow2(
|
A.FilterMap(F.Flow2(
|
||||||
O.FromPredicate(isPrime),
|
O.FromPredicate(isPrime),
|
||||||
@@ -132,12 +145,13 @@ func BenchmarkFilterMap(b *testing.B) {
|
|||||||
result = append(result, value/2)
|
result = append(result, value/2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
benchResult = result
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
b.Run("functional isEven", func(b *testing.B) {
|
b.Run("functional isEven", func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
F.Pipe1(
|
benchResult = F.Pipe1(
|
||||||
data,
|
data,
|
||||||
A.FilterMap(F.Flow2(
|
A.FilterMap(F.Flow2(
|
||||||
O.FromPredicate(isEven),
|
O.FromPredicate(isEven),
|
||||||
@@ -155,6 +169,9 @@ func BenchmarkFilterMap(b *testing.B) {
|
|||||||
result = append(result, value/2)
|
result = append(result, value/2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
benchResult = result
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
globalResult = benchResult
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user