This file contains hidden or 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
package benchmarking | |
// Below is the Type casting based Solution | |
// | |
type CarRegular struct { | |
Name string | |
DistanceMoved int | |
} | |
type PersonRegular struct { |
This file contains hidden or 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
package benchmarking | |
// Subtractable is a type constraint that defines subtractable datatypes to be used in generic functions | |
type Subtractable interface { | |
int | int64 | float32 | |
} | |
// Moveable is the interace for moving a Entity | |
type Moveable[S Subtractable] interface { |
This file contains hidden or 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
goos: windows | |
goarch: amd64 | |
pkg: programmingpercy/benchgeneric | |
cpu: Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz | |
Benchmark_Subtract | |
Benchmark_Subtract/SubtractInt | |
Benchmark_Subtract/SubtractInt-4 1000000000 0.9002 ns/op | |
Benchmark_Subtract/SubtractInt-4 1000000000 0.8904 ns/op | |
Benchmark_Subtract/SubtractInt-4 1000000000 0.8277 ns/op | |
Benchmark_Subtract/SubtractInt-4 1000000000 0.8290 ns/op |
This file contains hidden or 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
package functions | |
import ( | |
"math/rand" | |
"testing" | |
"time" | |
) | |
// Benchmark_Subtract is used to determine the most performant solution to subtraction | |
func Benchmark_Subtract(b *testing.B) { |
This file contains hidden or 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
package functions | |
// Subtract will subtract the second value from the first | |
func SubtractInt(a, b int) int { | |
return a - b | |
} | |
// Subtract64 will subtract the second value from the first | |
func SubtractInt64(a, b int) int { | |
return a - b |
This file contains hidden or 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
func FuzzTestHTTPHandler(f *testing.F) { | |
// Create a new server hosting our calculate func | |
srv := httptest.NewServer(http.HandlerFunc(CalculateHighest)) | |
defer srv.Close() | |
// Create example values for the fuzzer | |
testCases := []ValuesRequest{ | |
ValuesRequest{[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, | |
ValuesRequest{[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}}, | |
ValuesRequest{[]int{-50, -9, -8, -7, -6, -5, -4, -3, -2, -1}}, |
This file contains hidden or 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
func FuzzTestHTTPHandler(f *testing.F) { | |
// Create a new server hosting our calculate func | |
srv := httptest.NewServer(http.HandlerFunc(CalculateHighest)) | |
defer srv.Close() | |
// Add Corpus Seeds | |
testCases := []ValuesRequest{ | |
ValuesRequest{[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, | |
ValuesRequest{[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}}, | |
ValuesRequest{[]int{-50, -9, -8, -7, -6, -5, -4, -3, -2, -1}}, |
This file contains hidden or 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
func FuzzTestHTTPHandler(f *testing.F) { | |
// Create a new server hosting our calculate func | |
srv := httptest.NewServer(http.HandlerFunc(CalculateHighest)) | |
defer srv.Close() | |
// Create example values for the fuzzer | |
testCases := []ValuesRequest{ | |
ValuesRequest{[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, | |
ValuesRequest{[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}}, | |
ValuesRequest{[]int{-50, -9, -8, -7, -6, -5, -4, -3, -2, -1}}, |
This file contains hidden or 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
func MultipleInputs(a, b int, name string) { | |
// ... fancy code goes here | |
} | |
func FuzzMultipleInputs(f *testing.F) { | |
// We can add Multiple Seeds, but it has to be the same order as the input parameters for MultipleInputs | |
f.Add(10,20,"John the Ripper") | |
f.Fuzz(func(t *testing.T,a int,b int,name string){ | |
MultipleInputs(a,b,name) | |
}) |
This file contains hidden or 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
// How to define a Unit Test | |
func TestCalculateHighest(t *testing.T){ | |
} | |
// To define a Fuzz, we use Fuzz and testing.F | |
func FuzzTestHTTPHandler(f *testing.F) { | |
} |