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
package main | |
import ( | |
"testing" | |
) | |
func Benchmark_Big(b *testing.B) { | |
b.Run("return by value", func(b *testing.B) { | |
var big bigStruct | |
for n := 0; n < b.N; n++ { |
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
package main | |
import "time" | |
type bigStruct struct { | |
Var1 [1048576]float64 | |
Var2 [1048576]float64 | |
Var3 [1048576]float64 | |
Var4 [1048576]float64 | |
Var5 [1048576]float64 |
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
go test -run=. -bench=Benchmark -benchmem | |
goos: linux | |
goarch: amd64 | |
pkg: github.com/sayden/go-research/returning_values | |
Big/return_by_value-8 100 11740818 ns/op 50834966 B/op 1 allocs/op | |
Big/return_by_named_value-8 200 8701993 ns/op 50583306 B/op 1 allocs/op | |
Big/return_pointer-8 300 4188061 ns/op 50331648 B/op 1 allocs/op | |
Big/return_named_pointer-8 1000 3172411 ns/op 50331653 B/op 1 allocs/op |
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
package main | |
import ( | |
"context" | |
"encoding/json" | |
"github.com/juju/errors" | |
"github.com/thehivecorporation/log" | |
"net/http" | |
"time" | |
) |
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
package main | |
import ( | |
"context" | |
"encoding/json" | |
"github.com/juju/errors" | |
"github.com/thehivecorporation/log" | |
"net/http" | |
"time" | |
) |
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
package main | |
import ( | |
"encoding/json" | |
"github.com/thehivecorporation/log" | |
"net/http" | |
"time" | |
) | |
type res struct { |
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
package main | |
import ( | |
"github.com/thehivecorporation/log" | |
"math/rand" | |
"time" | |
) | |
func main() { | |
ch := make(chan struct{}) |
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
package time_profile | |
import "testing" | |
func Benchmark_NewTimer(b *testing.B) { | |
ch := newTimer() | |
for n := 0; n < b.N; n++ { | |
ch <- struct{}{} | |
} |
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
package time_profile | |
import "time" | |
func newTimer() chan struct{} { | |
ch := make(chan struct{}) | |
go func(ch chan struct{}) { | |
waitduration := 5000 * time.Millisecond |
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
package time_profile | |
import "testing" | |
func Benchmark_TimeAfter(b *testing.B) { | |
ch := timeAfter() | |
for n := 0; n < b.N; n++ { | |
ch <- struct{}{} | |
} |
NewerOlder