-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeed5.js
87 lines (67 loc) · 2.4 KB
/
speed5.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
var count = 0;
var idx;
var txn;
var start = new Date();
var db, dbname;
for (dbname in catalog.db)
db = new Db(dbname), db.drop();
db = new Db("tstdb", {onDisk:true});
var store = db.createDocStore("collection", {onDisk:true});
var index = store.createIndex("speedIdx", {onDisk:true, idxType:1}, {doc:"fwd:dbl"});
while(count<1000) {
txn = new Txn();
var id, cnt;
idx = 0;
var docIds = [];
txn = new Txn();
var array = [], key = [], keys;
while(idx<1000) {
// print ("batch: ", count, " item: ", idx);
array = {
doc : Math.random() * (count * 1000 + idx),
cnt : count,
idx : idx,
/* text0 : "This is a test string designed to make this record bigger0",
text1 : "This is a test string designed to make this record bigger1",
text2 : "This is a test string designed to make this record bigger2",
text3 : "This is a test string designed to make this record bigger3",
text4 : "This is a test string designed to make this record bigger4",
text5 : "This is a test string designed to make this record bigger5",
text6 : "This is a test string designed to make this record bigger6",
text7 : "This is a test string designed to make this record bigger7",
text8 : "This is a test string designed to make this record bigger8",
text9 : "This is a test string designed to make this record bigger9"
*/ };
idx += 1;
}
docIds = txn(store.append(array));
var nxt;
for( idx = 0; idx<1000;idx++) {
keys = index.buildKey(docIds[idx], array[idx].doc);
for( nxt = 0; nxt < keys.length; nxt++ )
txn.index.insertKey(docIds[idx], keys[nxt++]);
}
print("keys:", keys, " docId: ", docIds[idx - 1]);
txn.commit();
count += 1;
// print ("batch: ", count);
}
var stop = new Date();
var ins = (stop - start) / 1000.;
start = stop;
var cursor, doc;
cursor = index.createCursor();
var reccnt = 0;
var prev = 0;
while( doc = cursor.move(CursorOp.opNext)) {
if (!(reccnt % 2500))
print("idx: ", reccnt, " docId: ", doc.docId, "\tkey: ", doc.doc);
if (doc.doc < prev)
print ("out of order record #", reccnt, "\tkey: ", doc.doc, " prev: ", prev);
prev = doc.doc;
reccnt += 1;
}
var stop = new Date();
print ("insert: ", ins, " seconds");
print ("found: ", reccnt, " should be 1000000");
print ("sort verify: ", (stop - start) / 1000., " seconds");