aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/bench2_test.go
blob: 0dd60fd829bb83fbe497a9838e6c73e462729c6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// +build !go1.2

package leveldb

import (
    "sync/atomic"
    "testing"
)

func BenchmarkDBReadConcurrent(b *testing.B) {
    p := openDBBench(b, false)
    p.populate(b.N)
    p.fill()
    p.gc()
    defer p.close()

    b.ResetTimer()
    b.SetBytes(116)

    b.RunParallel(func(pb *testing.PB) {
        iter := p.newIter()
        defer iter.Release()
        for pb.Next() && iter.Next() {
        }
    })
}

func BenchmarkDBReadConcurrent2(b *testing.B) {
    p := openDBBench(b, false)
    p.populate(b.N)
    p.fill()
    p.gc()
    defer p.close()

    b.ResetTimer()
    b.SetBytes(116)

    var dir uint32
    b.RunParallel(func(pb *testing.PB) {
        iter := p.newIter()
        defer iter.Release()
        if atomic.AddUint32(&dir, 1)%2 == 0 {
            for pb.Next() && iter.Next() {
            }
        } else {
            if pb.Next() && iter.Last() {
                for pb.Next() && iter.Prev() {
                }
            }
        }
    })
}