-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
singleBench.js
95 lines (93 loc) · 2.53 KB
/
singleBench.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const {
makeClient,
connectClient,
initDb,
disconnectClient,
dropDb,
initCollection,
createCollection,
dropCollection,
makeLoadJSON,
makeLoadTweets
} = require('../../driverBench/common');
function makeSingleBench(suite) {
suite
.benchmark('runCommand', benchmark =>
benchmark
.taskSize(0.16)
.setup(makeClient)
.setup(connectClient)
.setup(initDb)
.task(async function () {
for (let i = 0; i < 10000; ++i) {
await this.db.command({ hello: true });
}
})
.teardown(disconnectClient)
)
.benchmark('findOne', benchmark =>
benchmark
.taskSize(16.22)
.setup(makeLoadJSON('tweet.json'))
.setup(makeClient)
.setup(connectClient)
.setup(initDb)
.setup(dropDb)
.setup(initCollection)
.setup(makeLoadTweets(true))
.task(async function () {
for (let _id = 0; _id < 10000; ++_id) {
await this.collection.findOne({ _id });
}
})
.teardown(dropDb)
.teardown(disconnectClient)
)
.benchmark('smallDocInsertOne', benchmark =>
benchmark
.taskSize(2.75)
.setup(makeLoadJSON('small_doc.json'))
.setup(makeClient)
.setup(connectClient)
.setup(initDb)
.setup(dropDb)
.setup(initDb)
.setup(initCollection)
.setup(createCollection)
.beforeTask(dropCollection)
.beforeTask(createCollection)
.beforeTask(initCollection)
.task(async function () {
for (let i = 0; i < 10000; ++i) {
const doc = Object.assign({}, this.doc);
await this.collection.insertOne(doc);
}
})
.teardown(dropDb)
.teardown(disconnectClient)
)
.benchmark('largeDocInsertOne', benchmark =>
benchmark
.taskSize(27.31)
.setup(makeLoadJSON('large_doc.json'))
.setup(makeClient)
.setup(connectClient)
.setup(initDb)
.setup(dropDb)
.setup(initDb)
.setup(initCollection)
.setup(createCollection)
.beforeTask(dropCollection)
.beforeTask(createCollection)
.beforeTask(initCollection)
.task(async function () {
for (let i = 0; i < 10; ++i) {
const doc = Object.assign({}, this.doc);
await this.collection.insertOne(doc);
}
})
.teardown(dropDb)
.teardown(disconnectClient)
);
}
module.exports = { makeSingleBench };