Skip to content

Instantly share code, notes, and snippets.

View zhenjl's full-sized avatar

Jian Zhen zhenjl

View GitHub Profile
@zhenjl
zhenjl / mutexvscas.go
Last active August 29, 2015 14:02
A quick test of mutex vs CAS, using 1 or more goroutines and 1 or more CPU cores
// Results are in
// https://docs.google.com/spreadsheets/d/1R-KVBfKxM3KL2G4AuPtxr4SS_1iQYfrPTo0r5EZOFXs/pubhtml
package mutexvscas
import (
"testing"
"sync"
"log"
"time"
// First: go get github.com/golang/glog
// Then : go test -v -vmodule=*=3 -logtostderr netgrace_test.go
// This test package shows how to gracefully shutdown a net.Listener.
package netgrace
import (
"bufio"
"fmt"
"github.com/golang/glog"
package main
import (
"bytes"
"code.google.com/p/snappy-go/snappy"
"github.com/cznic/zappy"
"compress/gzip"
"compress/lzw"
"flag"
"fmt"
--- Output of using **gccgo -O3** ---
BenchmarkOffset2 50000000 27.6 ns/op
BenchmarkOffset 50000000 32.0 ns/op
BenchmarkRange 500000000 4.46 ns/op
BenchmarkUnrolled 200000000 8.92 ns/op
BenchmarkCopy 500000000 7.52 ns/op
BenchmarkRangeCopy 100000000 13.9 ns/op
BenchmarkCopyUnrolled 200000000 8.91 ns/op
--- Output of using standard go compiler ---
package codesearch
import (
"bufio"
"compress/gzip"
"encoding/binary"
"fmt"
"github.com/reducedb/cityhash"
"log"
"os"
# h = operations
# i = # of bits for bitmap 1
# j = # of bits for bitmap 2
# k = random distance between bits for bitmap 1 (0-k) - indicates sparsity
# l = random distance between bits for bitmap 1 (0-l) - indicates sparsity
for h in and or xor andnot
do
for i in 100 10000 1000000
do
for j in 100 10000 1000000
@zhenjl
zhenjl / Updated Bloom Filter Benchmark
Last active December 22, 2015 18:49
These new benchmark results are after I removed the "make([]uint, this.k)" from bits() function. Instead we just do a make at the New() time, and re-use the same slice for each add/check.
Partitioned Bloom Filter
------------------------
BenchmarkBloomFNV64 1000000 1032 ns/op
BenchmarkBloomCRC64 1000000 1032 ns/op
BenchmarkBloomMurmur3 1000000 1008 ns/op (ignore, invalid due to murmur3 impl or incorrect usage)
BenchmarkBloomCityHash 1000000 3345 ns/op (ignore, most likely slow due to my cityhash impl)
BenchmarkBloomMD5 1000000 2349 ns/op
BenchmarkBloomSha1 1000000 2551 ns/op
Standard Bloom Filter
Testing fnv.New64() with size 235886
m = 3391472, n = 235886, k = 10, s = 339148, p = 0.500000, e = 0.001000
Total items: 235886
Bits in partition 0: 170044 (50.1%)
Bits in partition 1: 170171 (50.2%)
Bits in partition 2: 169914 (50.1%)
Bits in partition 3: 170022 (50.1%)
Bits in partition 4: 170144 (50.2%)
Bits in partition 5: 169979 (50.1%)
Bits in partition 6: 170080 (50.1%)
Command: go test -bench=.
Machine: Macbook Air 10.8.4 1.8GHz Intel Core i5 4GB 1600MHz DDR3
BSON (message size = 152)
----
BenchmarkMarhsal 200000 6638 ns/op
BenchmarkUnmarshall 200000 9599 ns/op
MsgPack (message size = 126)
@zhenjl
zhenjl / perlin1d.go
Created July 24, 2013 21:54
Generates 1d perlin noise in Go
/*
* Based on algorithm given at http://freespace.virgin.net/hugo.elias/models/m_perlin.htm
*
* Borrowed heavily from https://github.com/iand/perlin/blob/master/perlin.go
*
* MIT License http://opensource.org/licenses/MIT
*/
package main