Skip to content

Instantly share code, notes, and snippets.

@bmatsuo
bmatsuo / main.go
Last active March 15, 2016 15:33
My use case for Go experssion text-objects in vim. This is a fairly dumb example. But the pattern of iteration between different versions of a function (Version1, Version2, and Version3) in not completely uncommon for me. I find myself in situations function argument expressions must be extracted to produce a more complete or general result.
package main
import (
"io"
"os"
"strings"
)
func main() {
Version1()
@bmatsuo
bmatsuo / README.md
Last active August 29, 2015 14:23
This gist demonstrates strange behavior from strace and a crash that it triggers in fabricate.

The build script in this gist occasionally crashes compiling even the simplest of Go programs (main.go) with the traceback in stderr.log. The strace log corresponding to the crash is in strace.txt.

  • strace -- version 4.8
  • go -- version 1.4.2
  • fabricate.py -- SimonAlphie/fabricate@6ccc79753fa30a66579caf2f3c9a1cbbf2f468a4
  • python -- 2.7.6
  • Ubuntu -- 14.04 LTS 64-bit (3.13.0-43-generic)

The build script needs to be invoked with the -c flag because the behavior does not always exhibit.

#Benchmark results created with go test

Test data was generated on a 4-core i7 (16GB ram) Lenovo ThinkPad running Ubuntu 14.04.

Each benchmark was run for 10 seconds (10x the default) to reduce noise seen when the benchmarks ran for 1 second.

go test -run=NONE -bench=Reader -benchtime=10s

I've included the raw test results for each of the master branch, the original pull request, and the pull request modified to avoid heap allocation by inlining the copyWriter struct literal. For the latter two I've included benchcmp output comparing them to the master branch. There is also a comparison between the pull request and it's modified form.

# benchcmp bench.new.txt bench.newinline.txt
benchmark old ns/op new ns/op delta
BenchmarkReaderManpage 19525 19398 -0.65%
BenchmarkReaderManpage_buffered 19605 19347 -1.32%
BenchmarkReaderManpageNoCopy 19686 19314 -1.89%
BenchmarkReaderJSON 314747 319364 +1.47%
BenchmarkReaderJSON_buffered 330732 333882 +0.95%
BenchmarkReaderJSONNoCopy 332856 336380 +1.06%
BenchmarkReaderRandom 1893232 1870011 -1.23%
@bmatsuo
bmatsuo / bench.newinline.txt
Created November 25, 2014 01:32
after inlining the copyWriter struct literal into WriteTo
PASS
BenchmarkReaderManpage 1000000 19398 ns/op 131.45 MB/s
BenchmarkReaderManpage_buffered 1000000 19347 ns/op 131.80 MB/s
BenchmarkReaderManpageNoCopy 1000000 19314 ns/op 132.02 MB/s
BenchmarkReaderJSON 50000 319364 ns/op 76.49 MB/s
BenchmarkReaderJSON_buffered 50000 333882 ns/op 67.62 MB/s
BenchmarkReaderJSONNoCopy 50000 336380 ns/op 67.12 MB/s
BenchmarkReaderRandom 10000 1870011 ns/op 5608.70 MB/s
BenchmarkReaderRandom_buffered 10000 1843386 ns/op 5689.01 MB/s
BenchmarkReaderRandomNoCopy 10000 2748211 ns/op 3815.95 MB/s
@bmatsuo
bmatsuo / bench.new.txt
Last active August 29, 2015 14:10
without inlining the copyWriter struct literal
PASS
BenchmarkReaderManpage 1000000 19525 ns/op 130.60 MB/s
BenchmarkReaderManpage_buffered 1000000 19605 ns/op 130.07 MB/s
BenchmarkReaderManpageNoCopy 1000000 19686 ns/op 129.53 MB/s
BenchmarkReaderJSON 50000 314747 ns/op 77.61 MB/s
BenchmarkReaderJSON_buffered 50000 330732 ns/op 68.27 MB/s
BenchmarkReaderJSONNoCopy 50000 332856 ns/op 67.83 MB/s
BenchmarkReaderRandom 10000 1893232 ns/op 5539.91 MB/s
BenchmarkReaderRandom_buffered 10000 1842477 ns/op 5691.82 MB/s
BenchmarkReaderRandomNoCopy 10000 2765457 ns/op 3792.16 MB/s
@bmatsuo
bmatsuo / bench.old.txt
Last active August 29, 2015 14:10
Reader benchmarks from the master branch (9438ff5)
PASS
BenchmarkReaderManpage 1000000 20223 ns/op 126.09 MB/s
BenchmarkReaderManpage_buffered 1000000 20176 ns/op 126.39 MB/s
BenchmarkReaderManpageNoCopy 1000000 20179 ns/op 126.36 MB/s
BenchmarkReaderJSON 50000 320459 ns/op 76.23 MB/s
BenchmarkReaderJSON_buffered 50000 332016 ns/op 68.00 MB/s
BenchmarkReaderJSONNoCopy 50000 334736 ns/op 67.45 MB/s
BenchmarkReaderRandom 10000 1859415 ns/op 5640.66 MB/s
BenchmarkReaderRandom_buffered 10000 1837270 ns/op 5707.95 MB/s
BenchmarkReaderRandomNoCopy 10000 2782352 ns/op 3769.13 MB/s
@bmatsuo
bmatsuo / snappy-go-index.err
Created September 8, 2014 01:55
This gist demonstrates several panics in the snappy-go package resulting from passing the Decode function malformed input. The snappy-go rev is 12e4b4183793, current at the time these tests were run.
panic: runtime error: index out of range
goroutine 16 [running]:
runtime.panic(0x4b9d80, 0x546cbc)
/usr/local/go/src/pkg/runtime/panic.c:279 +0xf5
code.google.com/p/snappy-go/snappy.Decode(0x0, 0x0, 0x0, 0x7f713339ceb5, 0xb, 0xb, 0x0, 0x0, 0x0, 0x0, ...)
/home/bryan/src/code.google.com/p/snappy-go/snappy/decode.go:49 +0xb0c
main.main()
/home/bryan/src/github.com/bmatsuo/sandbox/snappy-go-panic/snappy-go-index/main.go:11 +0x9c
@bmatsuo
bmatsuo / README.md
Last active August 29, 2015 14:04
go-snappystream benchmark comparisons for branch bmatsuo:snappy-go/optimize

Benchmarks were given two seconds to run. Allocations were recorded for each benchmark.

go test -test.benchtime=2s -test.benchmem=true -run=NONE -bench=. > [old,new].bench.txt

Benchmarks are compared with benchcmp

benchcmp old.bench.txt new.bench.txt

@bmatsuo
bmatsuo / opendbi.go
Created June 11, 2014 19:11
This results in a runtime panic "opening dbi :MDB_BAD_VALSIZE: Too big key/data, key is empty, or wrong DUPFIXED size"
package main
import (
"log"
"os"
mdb "github.com/szferi/gomdb"
)
func main() {