Skip to content

Instantly share code, notes, and snippets.

@bmatsuo
bmatsuo / desired_test.go
Created January 10, 2012 05:58
Golang "testing" file:line prefix
package main
import (
"fmt"
"path/filepath"
"runtime"
"testing"
)
func flushTestConnections() {}
@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 / vmsetup.sh
Last active December 28, 2015 04:59
#!/bin/env bash
# usage: bash <(curl https://gist.github.com/bmatsuo/7446833/raw)
sudo apt-get update
sudo apt-get install ssh git curl vim
git clone git@github.com:bmatsuo/home.git
bash -c 'cd home && bash install.sh'
@bmatsuo
bmatsuo / popenrunner.rb
Created September 8, 2011 23:37
Windows capable PopenRunner subclass for the handbrake ruby gem.
require "rubygems"
require "handbrake"
require 'rbconfig'
$on_mswin = Config::CONFIG['target_os'].match(/^mingw/)
require 'win32/open3' if $on_mswin
class MyRunner < HandBrake::CLI::PopenRunner
def command(args)
return super if !$on_mswin
@bmatsuo
bmatsuo / whatcd_singleep_of_the_w.user.js
Created October 10, 2010 02:12
Single/EP of the week that looks like the Featured Album box.
// ==UserScript==
// @name What.cd Single/EP of the Week
// @namespace http://google.com
// @description See the latest Single/EP of the week on the what.cd homepage.
// @include http*://*what.cd/index.php
// ==/UserScript==
//Thanks to dieselpowered for making it more like the Featured Album box!
function getElementsByClassName(classname, node) {
if(!node) node = document.getElementsByTagName("body")[0];
@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