-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeed3.js
89 lines (68 loc) · 2.43 KB
/
speed3.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
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:0}, {doc:"fwd:dbl"});
while(count<1000) {
var id, cnt;
idx = 0;
var docIds = [];
// txn = jsdb_beginTxn();
var array = [], key;
while(idx<1000) {
// print ("batch: ", count, " item: ", idx);
array[idx] = {
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 = store.writeDocs(array);
var nxt;
for( idx = 0; idx<1000;idx++) {
// keys = index.buildKey(docIds[idx], array[idx].doc);
// for( nxt = 0; nxt < keys.length; nxt++ )
key = index.insertKey(docIds[idx], array[idx].doc);
}
print("key: [", key, "] docId: ", docIds[idx - 1]);
// jsdb_commitTxn();
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;
var docId;
while( docId = cursor.move(CursorOp.opNext)) {
key = cursor.keyAt();
if (!(reccnt % 2500))
print("docId: ", docId, "\tkey: [", key, "]");
if ( key < prev)
print ("out of order record #", reccnt, " docId: ", doc.docId, "\tkey: ", key, " prev: ", prev);
prev = key;
reccnt += 1;
}
var stop = new Date();
print ("insert: ", ins, " seconds");
print ("found: ", reccnt, " should be 1000000");
print ("sort verify: ", (stop - start) / 1000., " seconds");