Skip to content

Instantly share code, notes, and snippets.

View yifan-gu's full-sized avatar

Yifan Gu yifan-gu

  • Anchorage Digital
  • San Francisco
View GitHub Profile
testing: warning: no tests to run
PASS
BenchmarkHttpSync 2 1040816732 ns/op
BenchmarkHttpAsync 1 1168044579 ns/op
BenchmarkTCPSync 1 1021137163 ns/op
BenchmarkTCPAsync 1 1125243129 ns/op
@yifan-gu
yifan-gu / gist:8046382
Created December 19, 2013 21:15
about synchronization in go
according to http://golang.org/ref/mem (especially the last example)
Will BenchmakTCP be guarantted to read tcpStarted = true next time?
Will server be guaranteed to Listen before client's Dial??
func BenchmarkTCP(b *testing.B) {
done := make(chan bool, 10)
if !tcpStarted {
go startServer()
@yifan-gu
yifan-gu / gist:8050410
Created December 20, 2013 04:26
no encoder
BenchmarkHttpSync 2 607772481 ns/op
BenchmarkHttpAsync 2 572791120 ns/op
BenchmarkTCPSync 2 572156303 ns/op
BenchmarkTCPAsync 2 566128710 ns/op
BenchmarkTcpDummySync 10 158858648 ns/op
BenchmarkHTTP 5 473381980 ns/op
BenchmarkTCP 10 134515019 ns/o
@yifan-gu
yifan-gu / gist:8118625
Created December 24, 2013 23:02
simple flow
message {
msgType (func name)
param
result
}
client:
select {
case <-send(encode(message))
@yifan-gu
yifan-gu / gist:8130307
Created December 26, 2013 05:57
repeated vs seperate field
2 * int64 and 1 * int32
BenchmarkPreAcceptProtoMarshal 5000000 480 ns/op 220.38 MB/s
5 * int32
BenchmarkPreAcceptProtoMarshal 5000000 584 ns/op 188.23 MB/s
repeated(slice) type
BenchmarkPreAcceptProtoMarshal 1000000 1282 ns/op 266.76 MB/s
@yifan-gu
yifan-gu / gist:8131355
Last active January 1, 2016 10:29
bench for message layer
BenchmarkNoSerializedServer 10 154370813 ns/op
BenchmarkSerializedServer 10 234600748 ns/op
compared with original rpc:
BenchmarkHttpSync 2 591041878 ns/op
BenchmarkHttpAsync 2 595159969 ns/op
BenchmarkTCPSync 2 612891027 ns/op
BenchmarkTCPAsync 2 623569721 ns/op
@yifan-gu
yifan-gu / gist:8274539
Created January 5, 2014 22:03
about gogoprotobuf on slice when len = 0
type A struct {
slice []int
}
a = &A{make([]int, 0)}
bytes, _ := a.Marshal()
b := new(A) // b.slice == nil
b.Unmarshal(bytes)
const writeOp = 0x100
const {
GET = iota
CONTAINS = iota
...
WRITE = writeOp
DELETE = writeOp + 1
UPDATE = writeOP + 2
...
@yifan-gu
yifan-gu / result.sh
Last active August 29, 2015 13:56
if reaching EOF, splice won't block
$ go build testsplice.go
$ echo "hello splice" | ./testsplice
$ splicing... buffer size: 4096
recv: hello splice
count: 13
finish
package main
import (
"fmt"
"net"
"os"
"syscall"
"time"
)