UNPKG

2.83 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.list({
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 < 5; 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 buildFiveHundredEntries(instance)
59
60 return fiveHundredEntries
61
62 function fiveHundredEntries (done) {
63 var result = instance.list({
64 bigCounter: '99',
65 small3: 99
66 })
67 if (!result) {
68 throw new Error('muahah')
69 }
70 process.nextTick(done)
71 }
72})()
73
74var fiveHundredEntriesAndProperties = (function () {
75 var instance = bloomrun({ indexing: 'depth' })
76 buildFiveHundredEntries(instance)
77
78 return fiveHundredEntriesAndProperties
79
80 function fiveHundredEntriesAndProperties (done) {
81 var result = instance.list({
82 bigCounter: '99',
83 small3: 99,
84 something: 'else'
85 })
86 if (!result) {
87 throw new Error('muahah')
88 }
89 process.nextTick(done)
90 }
91})()
92
93var patrunFiveHundredEntriesAndProperties = (function () {
94 var instance = patrun()
95 buildFiveHundredEntries(instance)
96
97 return patrunFiveHundredEntriesAndProperties
98
99 function patrunFiveHundredEntriesAndProperties (done) {
100 var result = instance.list({
101 bigCounter: '99',
102 small3: 99,
103 something: 'else'
104 })
105 if (!result) {
106 throw new Error('muahah')
107 }
108 process.nextTick(done)
109 }
110})()
111
112var patrunThreeEntries = (function () {
113 var instance = patrun()
114
115 instance.add({
116 hello: 'world',
117 answer: 42
118 }, 'hello')
119
120 instance.add({
121 hello: 'matteo',
122 answer: 42
123 }, 'hello')
124
125 instance.add({
126 something: 'else',
127 answer: 42
128 }, 'hello')
129
130 return patrunThreeEntries
131
132 function patrunThreeEntries (done) {
133 var result = instance.list({
134 something: 'else',
135 answer: 42
136 })
137 if (!result) {
138 throw new Error('muahah')
139 }
140 process.nextTick(done)
141 }
142})()
143
144var run = bench([
145 threeEntries,
146 fiveHundredEntries,
147 fiveHundredEntriesAndProperties,
148 patrunThreeEntries,
149 patrunFiveHundredEntriesAndProperties
150], 100000)
151
152run(run)