UNPKG

2.87 kBJavaScriptView Raw
1'use strict'
2
3var bench = require('fastbench')
4var bloomrun = require('../')
5var patrun = require('patrun')
6
7var threeEntries = (function () {
8 var instance = bloomrun({ indexing: 'depth' })
9
10 instance.add({
11 hello: 'world',
12 answer: 42
13 })
14
15 instance.add({
16 hello: 'matteo',
17 answer: 42
18 })
19
20 instance.add({
21 something: 'else',
22 answer: 42
23 })
24
25 return threeEntries
26
27 function threeEntries (done) {
28 var result = instance.lookup({
29 something: 'else',
30 answer: 42
31 })
32 if (!result) {
33 throw new Error('muahah')
34 }
35 process.nextTick(done)
36 }
37})()
38
39function buildFiveHundredEntries (instance) {
40 var obj
41
42 // this creates 100 buckets with 5 items each
43 for (var i = 0; i < 100; i++) {
44 for (var k = 0; k < 4; k++) {
45 obj = {
46 bigCounter: '' + i
47 }
48 obj['small' + k] = i
49 instance.add(obj, obj)
50 }
51 }
52
53 return instance
54}
55
56var fiveHundredEntries = (function () {
57 var instance = bloomrun({ indexing: 'depth' })
58
59 buildFiveHundredEntries(instance)
60
61 return fiveHundredEntries
62
63 function fiveHundredEntries (done) {
64 var result = instance.lookup({
65 bigCounter: '99',
66 small3: 99
67 })
68 if (!result) {
69 throw new Error('muahah')
70 }
71 process.nextTick(done)
72 }
73})()
74
75var fiveHundredEntriesAndProperties = (function () {
76 var instance = bloomrun({ indexing: 'depth' })
77 buildFiveHundredEntries(instance)
78
79 return fiveHundredEntriesAndProperties
80
81 function fiveHundredEntriesAndProperties (done) {
82 var result = instance.lookup({
83 bigCounter: '99',
84 small3: 99,
85 something: 'else'
86 })
87 if (!result) {
88 throw new Error('muahah')
89 }
90 process.nextTick(done)
91 }
92})()
93
94var patrunFiveHundredEntriesAndProperties = (function () {
95 var instance = patrun({ gex: true })
96 buildFiveHundredEntries(instance)
97
98 return patrunFiveHundredEntriesAndProperties
99
100 function patrunFiveHundredEntriesAndProperties (done) {
101 var result = instance.find({
102 bigCounter: '99',
103 small3: 99,
104 something: 'else'
105 })
106 if (!result) {
107 throw new Error('muahah')
108 }
109 process.nextTick(done)
110 }
111})()
112
113var patrunThreeEntries = (function () {
114 var instance = patrun({ gex: true })
115
116 instance.add({
117 hello: 'world',
118 answer: 42
119 }, 'hello')
120
121 instance.add({
122 hello: 'matteo',
123 answer: 42
124 }, 'hello')
125
126 instance.add({
127 something: 'else',
128 answer: 42
129 }, 'hello')
130
131 return patrunThreeEntries
132
133 function patrunThreeEntries (done) {
134 var result = instance.find({
135 something: 'else',
136 answer: 42
137 })
138 if (!result) {
139 throw new Error('muahah')
140 }
141 process.nextTick(done)
142 }
143})()
144
145var run = bench([
146 threeEntries,
147 fiveHundredEntries,
148 fiveHundredEntriesAndProperties,
149 patrunThreeEntries,
150 patrunFiveHundredEntriesAndProperties
151], 1000000)
152
153run(run)