szferi/gomdb — pull request #22 by bmatsuo (2014-04-21 11:41:56+00:00)
Title: Zero copy

Ok. "Zero copy" is overselling it a little. I added `GetVal()` methods which allow the user to get `MDB_val` types without copying their value to a `[]byte`. Not super useful in every situation. But nice if the user only needs to inspect only keys in some cases (when scanning the database) or if the key/value will be passed to another cgo function.

I also added some benchmarks. The first benchmark generates a bunch of random bytes. Those bytes are reused by other benchmarks to reduce runtime.

```sh
$ go test -test.bench=.*
# github.com/bmatsuo/gomdb
./mdb.c:8404:46: warning: data argument not used by format string [-Wformat-extra-args]
/usr/include/secure/_stdio.h:47:56: note: expanded from macro 'sprintf'
PASS
BenchmarkTxnPut	500000	2312 ns/op
--- BENCH: BenchmarkTxnPut
bench_test.go:301: initializing random source data
BenchmarkTxnGetRDONLY	1000000	1688 ns/op
BenchmarkTxnGetValRDONLY	1000000	1265 ns/op
BenchmarkCursorScanRDONLY	10	130606442 ns/op
BenchmarkCursorScanValRDONLY	50	37385878 ns/op
ok	github.com/bmatsuo/gomdb	60.261s
$
```