1 | var PouchDB = require('pouchdb'),
|
2 | pouch = new PouchDB('mydb', { adapter: 'memory' }),
|
3 | arraySize = 10000,
|
4 | totalIterations = 60000,
|
5 | results = [],
|
6 | gAsyncCount = 0,
|
7 | startTime,
|
8 | endTime,
|
9 | isIndexed = false;;
|
10 |
|
11 |
|
12 | function genRandomVal()
|
13 | {
|
14 | var text = "";
|
15 | var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
16 |
|
17 | for( var i=0; i < 20; i++ )
|
18 | text += possible.charAt(Math.floor(Math.random() * possible.length));
|
19 |
|
20 | return text;
|
21 | }
|
22 |
|
23 | function initializeDB() {
|
24 | gAsyncCount = 0;
|
25 |
|
26 | startTime = process.hrtime();
|
27 |
|
28 |
|
29 |
|
30 | for (var idx=0; idx < arraySize; idx++) {
|
31 | var v1 = '12345';
|
32 | var v2 = '23456';
|
33 |
|
34 | pouch.put({
|
35 | _id: idx,
|
36 | val: v1,
|
37 | val2: v2,
|
38 | val3: "more data 1234567890"
|
39 | }, function (err, newDoc) {
|
40 | if (++gAsyncCount == arraySize) {
|
41 | endTime = process.hrtime(startTime);
|
42 | var totalMS = endTime[0] * 1e3 + endTime[1] / 1e6;
|
43 | var rate = arraySize * 1000 / totalMS;
|
44 | rate = rate.toFixed(2);
|
45 | console.log("load (insert) : " + totalMS + "ms (" + rate + ") ops/s");
|
46 |
|
47 | testperfFind();
|
48 | }
|
49 | });
|
50 | }
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | function testperfFind() {
|
58 | var loopIterations = totalIterations;
|
59 |
|
60 | gAsyncCount = 0;
|
61 |
|
62 | startTime = process.hrtime();
|
63 |
|
64 | for (var idx=0; idx < loopIterations; idx++) {
|
65 | var customidx = Math.floor(Math.random() * arraySize) + 1;
|
66 |
|
67 | pouch.get(customidx, function (err, docs) {
|
68 | ++gAsyncCount;
|
69 |
|
70 | if (gAsyncCount == totalIterations) {
|
71 | endTime = process.hrtime(startTime);
|
72 | var totalMS = endTime[0] * 1e3 + endTime[1] / 1e6;
|
73 | var rate = (isIndexed?totalIterations*200:totalIterations) * 1000 / totalMS;
|
74 | rate = rate.toFixed(2);
|
75 | console.log("find (indexed : " + isIndexed + ") : " + totalMS + "ms (" + rate + ") ops/s");
|
76 | }
|
77 | });
|
78 | }
|
79 | }
|
80 |
|
81 | initializeDB();
|
82 |
|