Skip to content

Instantly share code, notes, and snippets.

Benchmark go 1.2 vs go 1.3:
name old time/op new time/op delta
JsonMarshall 1.91µs ± 2% 1.37µs ± 2% -28.23% (p=0.008 n=5+5)
JsonUnmarshal 2.70µs ± 2% 1.75µs ± 3% -35.18% (p=0.008 n=5+5)
name old alloc/op new alloc/op delta
JsonMarshall 221B ± 0% 218B ± 0% -1.36% (p=0.008 n=5+5)
JsonUnmarshal 518B ± 0% 475B ± 0% -8.37% (p=0.008 n=5+5)
name old allocs/op new allocs/op delta
@blanchonvincent
blanchonvincent / deck.go
Created July 5, 2019 06:26
medium - test package - white box vs black box - deck
package deck
import (
"errors"
"math/rand"
)
var Empty = errors.New("Empty deck")
type Deck struct {
@blanchonvincent
blanchonvincent / deck_wb_test.go
Created July 5, 2019 06:35
medium - test package - white box test
package deck
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestDeckShouldBeShuffledOnce(t *testing.T) {
var num uint8 = 5
@blanchonvincent
blanchonvincent / deck_benchmark_test.go
Created July 5, 2019 08:44
medium - test package - benchmark with custom metric
package deck
import (
"testing"
)
func BenchmarkGC(b *testing.B) {
b.ReportAllocs()
shuffled := 0
@blanchonvincent
blanchonvincent / deck_bb_test.go
Last active July 5, 2019 09:17
medium - test package - black box test
package deck_test
import (
"github.com/blanchonvincent/test-package/card"
"github.com/stretchr/testify/assert"
"testing"
)
func TestDeckCanDrawCards(t *testing.T) {
var num uint8 = 10
@blanchonvincent
blanchonvincent / unbuffered.go
Last active July 12, 2019 10:02
Medium - channel unbuffered channel
package main
import (
"sync"
"time"
)
func main() {
c := make(chan string)
@blanchonvincent
blanchonvincent / buffered.go
Created July 12, 2019 10:36
Medium - buffered channel
package main
import (
"sync"
"time"
)
func main() {
c := make(chan string, 2)
@blanchonvincent
blanchonvincent / bench_chan_buffer.go
Created July 12, 2019 14:17
Medium - Channel - Buffer Size Benchmark
package bench
import (
"sync"
"sync/atomic"
"testing"
)
func BenchmarkWithNoBuffer(b *testing.B) {
benchmarkWithBuffer(b, 0)
@blanchonvincent
blanchonvincent / main.go
Created July 16, 2019 18:28
Medium - init functions
package main
import (
_ "os"
)
func init() {
println(`init 1`)
}
@blanchonvincent
blanchonvincent / init.go
Created July 16, 2019 18:28
Medium - Init functions
package main
func init() {
println(`init 3`)
}