Skip to content

Commit 0a41b23

Browse files
Merge pull request #131 from logic-building/benchMarkTest
Added benchmark test for PMap with FixedOrder and Random Order of res…
2 parents 63b713d + 5057e53 commit 0a41b23

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

README.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ go install github.com/logic-building/functional-go/gofp
2121
```
2222
[[constraint]]
2323
name = "github.com/logic-building/functional-go"
24-
version = "8.13.0"
24+
version = "8.13.1"
2525
```
2626

2727
### Quick Start
@@ -280,7 +280,13 @@ Options on go:generate :
280280
26. Neg<Type>P : Returns true if num is less than zero, else false
281281
27. Odd<Type>P : Returns true if n is odd
282282
28. PMap<Type> : Similar to Map<Type> with additional feature - function(1st) argument runs concurrently for each item in the list(2nd argument)
283+
EX. PMapInt(squareInt, []int{v1, v2, v3})
284+
PMapInt(squareInt, []int{v1, v2, v3}, Optional{FixedPool: 2, RandomOrder: true})
285+
283286
29. PMap<InputType><OutputType>: Similar to Map<InputType><OutputType> with additional feature - function(1st) argument runs concurrently for each item in the list(2nd argument)
287+
EX. PMapIntInt64(plusOneIntInt64, []int{1, 2, 3}) // input: list(int), returns: list(int64)
288+
PMapIntInt64(plusOneIntInt64, []int{1, 2, 3}, Optional{FixedPool: 2, RandomOrder: true})
289+
284290
30. Pos<Type>P : Returns true if num is greater than zero, else false
285291
31. Range<Type> : Returns a new list of range between lower and upper value. Optional argument(3rd) will increment value by given number
286292
32. Reduce<Type> : Reduces a list to a single value by combining elements via a supplied function
@@ -302,6 +308,11 @@ Options on go:generate :
302308

303309
### Functions in generated code for struct (user defined type)
304310
```
311+
Note:
312+
Comparison logic for struct is based on == operator as long as the members of struct are of simple types.
313+
But reflect.DeepEqual is used for struct comparison if the struct contains any slices, maps.
314+
```
315+
```
305316
1. Difference : Returns a set that is the first set without elements of the remaining sets
306317
2. Difference<struct>By<Field>
307318
3. Distinct : Returns a new list with duplicates removed
@@ -959,10 +970,14 @@ distinct := fp.DistinctInt(list) // returns [8, 2, 0]
959970
### Test Coverage
960971
```
961972
Tests Passed : 1217
962-
ok functional-go/fp 0.015s coverage: 100.0% of statements
973+
ok functional-go/fp 0.015s coverage: 99.7% of statements
963974
ok functional-go/set 0.031s coverage: 100.0% of statements
964975
```
965-
976+
### Test Counts
977+
```
978+
go test ./... -v | grep -c RUN
979+
4762
980+
```
966981
### BenchMark test:
967982
```
968983
Model Identifier: MacBookPro11,5
@@ -987,3 +1002,15 @@ BenchmarkMapStr-8 1000000 49438 ns/op
9871002
PASS
9881003
ok functional-go/fp 67.567s
9891004
```
1005+
1006+
### Benchmark test for PMap with fixed order and random order
1007+
```
1008+
go test -benchtime=200x -bench=BenchmarkPMapInt
1009+
goos: darwin
1010+
goarch: amd64
1011+
pkg: github.com/logic-building/functional-go/fp
1012+
BenchmarkPMapInt-8 200 16224 ns/op
1013+
BenchmarkPMapIntRandomOrder-8 200 10091 ns/op
1014+
PASS
1015+
ok github.com/logic-building/functional-go/fp 4.549s
1016+
```

fp/benchmark_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package fp
2+
3+
import "testing"
4+
5+
func Fib(n int) int {
6+
if n < 2 {
7+
return n
8+
}
9+
return Fib(n-1) + Fib(n-2)
10+
}
11+
12+
func BenchmarkPMapInt(b *testing.B) {
13+
for n := 0; n < b.N; n++ {
14+
PMapInt(Fib, RangeInt(2, 10))
15+
}
16+
}
17+
18+
func BenchmarkPMapIntRandomOrder(b *testing.B) {
19+
for n := 0; n < b.N; n++ {
20+
PMapInt(Fib, RangeInt(2, 10), Optional{RandomOrder: true})
21+
}
22+
}

0 commit comments

Comments
 (0)