Skip to content

Instantly share code, notes, and snippets.

View odeke-em's full-sized avatar

Emmanuel T Odeke odeke-em

View GitHub Profile
@odeke-em
odeke-em / bench_test.go
Created February 19, 2018 09:18
Impetus for switching from generation of [256]uint8 to [256]int for math/bits Len*
package main
import "testing"
var len8tab = [256]uint8{
0x00, 0x01, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
@odeke-em
odeke-em / new.txt
Created February 17, 2018 23:45
Showing the difference between writeStr and io.Writer.Write
BenchmarkWrite1B-4 100000000 11.4 ns/op 2 B/op 0 allocs/op
BenchmarkWrite1B-4 100000000 10.5 ns/op 2 B/op 0 allocs/op
BenchmarkWrite1B-4 100000000 10.7 ns/op 2 B/op 0 allocs/op
BenchmarkWrite1B-4 100000000 11.8 ns/op 2 B/op 0 allocs/op
BenchmarkWrite1B-4 100000000 11.5 ns/op 2 B/op 0 allocs/op
BenchmarkWrite10B-4 100000000 27.5 ns/op 24 B/op 0 allocs/op
BenchmarkWrite10B-4 100000000 14.0 ns/op 24 B/op 0 allocs/op
BenchmarkWrite10B-4 100000000 13.5 ns/op 24 B/op 0 allocs/op
BenchmarkWrite10B-4 100000000 13.8 ns/op 24 B/op 0 allocs/op
BenchmarkWrite10B-4 100000000 13.5 ns/op 24 B/op 0 allocs/op
BenchmarkSetDelete-4 500 4017796 ns/op 6318207 B/op 251 allocs/op
BenchmarkSetDelete-4 20 50002573 ns/op 5196896 B/op 237 allocs/op
BenchmarkSetDelete-4 500 4189012 ns/op 6318139 B/op 251 allocs/op
BenchmarkSetDelete-4 500 4028421 ns/op 6319832 B/op 251 allocs/op
BenchmarkSetDelete-4 300 3419728 ns/op 6076823 B/op 250 allocs/op
BenchmarkSetDelete-4 500 2828081 ns/op 6318151 B/op 251 allocs/op
BenchmarkSetDelete-4 1000 3638473 ns/op 6217322 B/op 251 allocs/op
BenchmarkSetDelete-4 500 3446303 ns/op 6319831 B/op 251 allocs/op
BenchmarkSetDelete-4 1000 3779531 ns/op 6218172 B/op 252 allocs/op
BenchmarkSetDelete-4 500 3234770 ns/op 6318151 B/op 251 allocs/op
@odeke-em
odeke-em / database_sql-convert.go.diff
Last active November 2, 2017 10:23
Repro to support proposal to support parsing out `<nil>`
diff --git a/src/database/sql/convert.go b/src/database/sql/convert.go
index b79ec3f..bb384a9 100644
--- a/src/database/sql/convert.go
+++ b/src/database/sql/convert.go
@@ -402,11 +402,15 @@ func convertAssign(dest, src interface{}) error {
dv.SetUint(u64)
return nil
case reflect.Float32, reflect.Float64:
- s := asString(src)
- f64, err := strconv.ParseFloat(s, dv.Type().Bits())
@odeke-em
odeke-em / benchmp.md
Created October 27, 2017 21:58
Exhibit of the advantage of copy vs append
$ benchcmp old.txt new.txt 
benchmark          old ns/op     new ns/op     delta
BenchmarkBy*-4     319           99.4          -68.84%
BenchmarkBy*-4     318           138           -56.60%
BenchmarkBy*-4     321           88.7          -72.37%
BenchmarkBy*-4     320           90.2          -71.81%
BenchmarkBy*-4     319           85.9          -73.07%

benchmark          old allocs     new allocs     delta
@odeke-em
odeke-em / README.md
Created September 3, 2017 10:31
GDAX/Coinbase Websocket Feed
package main
import (
"flag"
"fmt"
"log"
"net"
"net/http"
"net/http/httputil"
"net/url"
@odeke-em
odeke-em / README.md
Created August 22, 2017 10:51
Uber Driver API implemented in Go

Go get it

go get -u -v github.com/orijtech/uber/v1

Requirements

You just need to have a serialized OAuth2.0 JSON configuration file saved in in $HOME/.uber/credentials.json

Running them

For each file, just do:

@odeke-em
odeke-em / deferbench_test.go
Last active March 2, 2018 20:51
Benchmarking invoking defer fn() vs fn()
package main
import (
"sync"
"testing"
)
type st struct {
sync.Mutex
@odeke-em
odeke-em / cmp_test.go
Created August 10, 2017 00:51
comparing var big.NewInt(0) vs allocating big.NewInt(0) everytime
package main
import (
"math/big"
"testing"
)
var bns = []*big.Int{
big.NewInt(0),
big.NewInt(10),