Skip to content

Instantly share code, notes, and snippets.

View zhenjl's full-sized avatar

Jian Zhen zhenjl

View GitHub Profile
<div zn-pages zn-pages-start="0" zn-pages-swipe>
<ul zn-pages-start="1">
<li style="background-color: #1abc9c; width: 250px">Pages</li>
<li style="background-color: #3498db">Main</li>
</ul>
<ul zn-pages-start="1">
<li ng-repeat="val in colors track by $id($index)" style="background-color: {{ val }}; text-align: center; margin: 0 auto">{{ val }}</li>
</ul>
<ul>
<li style="background-color: #95a5a6">Credits</li>
var container = znPageManager.container('zn-pages-container-0');
// or znPageManager.containers()[0]
$scope.slideLeft = function() { container.slideLeft(); };
$scope.slideRight = function() { container.slideRight(); };
$scope.slideDown = function() { container.slideDown(); };
$scope.slideUp = function() { container.slideUp(); };
$scope.slideHome = function() { container.slideHome(); };
@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
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)
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%)
@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
# 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
package codesearch
import (
"bufio"
"compress/gzip"
"encoding/binary"
"fmt"
"github.com/reducedb/cityhash"
"log"
"os"
--- 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 main
import (
"bytes"
"code.google.com/p/snappy-go/snappy"
"github.com/cznic/zappy"
"compress/gzip"
"compress/lzw"
"flag"
"fmt"