Skip to content

Instantly share code, notes, and snippets.

View sayden's full-sized avatar

Mario Castro sayden

View GitHub Profile
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++ {
package main
import "time"
type bigStruct struct {
Var1 [1048576]float64
Var2 [1048576]float64
Var3 [1048576]float64
Var4 [1048576]float64
Var5 [1048576]float64
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
package main
import (
"context"
"encoding/json"
"github.com/juju/errors"
"github.com/thehivecorporation/log"
"net/http"
"time"
)
package main
import (
"context"
"encoding/json"
"github.com/juju/errors"
"github.com/thehivecorporation/log"
"net/http"
"time"
)
package main
import (
"encoding/json"
"github.com/thehivecorporation/log"
"net/http"
"time"
)
type res struct {
package main
import (
"github.com/thehivecorporation/log"
"math/rand"
"time"
)
func main() {
ch := make(chan struct{})
package time_profile
import "testing"
func Benchmark_NewTimer(b *testing.B) {
ch := newTimer()
for n := 0; n < b.N; n++ {
ch <- struct{}{}
}
package time_profile
import "time"
func newTimer() chan struct{} {
ch := make(chan struct{})
go func(ch chan struct{}) {
waitduration := 5000 * time.Millisecond
@sayden
sayden / time_after_test.go
Created August 17, 2018 21:06
time after test
package time_profile
import "testing"
func Benchmark_TimeAfter(b *testing.B) {
ch := timeAfter()
for n := 0; n < b.N; n++ {
ch <- struct{}{}
}