generated from moul/golang-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
97 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package u | ||
|
||
// BoolPtr returns a pointer to a bool of value 'val'. | ||
func BoolPtr(val bool) *bool { | ||
return &val | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package u_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"moul.io/u" | ||
) | ||
|
||
func ExampleBoolPtr() { | ||
truePtr := u.BoolPtr(true) | ||
falsePtr := u.BoolPtr(false) | ||
fmt.Println("true ptr: ", *truePtr) | ||
fmt.Println("false ptr: ", *falsePtr) | ||
// Output: | ||
// true ptr: true | ||
// false ptr: false | ||
} | ||
|
||
func BenchmarkBoolPtr(b *testing.B) { | ||
b.Run("serial", func(b *testing.B) { | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
u.BoolPtr(true) | ||
} | ||
}) | ||
b.Run("parallel", func(b *testing.B) { | ||
b.ResetTimer() | ||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
u.BoolPtr(true) | ||
} | ||
}) | ||
}) | ||
} |