Skip to content

Commit fbb71a4

Browse files
committed
get speed2 and speed3 going
1 parent 1b20320 commit fbb71a4

File tree

5 files changed

+95
-7
lines changed

5 files changed

+95
-7
lines changed

js_dbindex.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ value_t fcnIdxInsKey(value_t *args, value_t thisVal, environment_t *env) {
5555
DbIndex *index;
5656
int cnt = vec_cnt(args), len;
5757
int idx = 0, off = sizeof(KeyValue);
58+
value_t docId = args[0];
5859

5960
s.bits = vt_status;
6061

@@ -72,9 +73,11 @@ value_t fcnIdxInsKey(value_t *args, value_t thisVal, environment_t *env) {
7273
index = (DbIndex *)(idxMap->arena + 1);
7374
keyValue = (KeyValue *)buff;
7475
memset(keyValue, 0, sizeof(KeyValue));
75-
val = args[0];
7676

77-
while (idx < cnt) {
77+
if ( docId.type == vt_docId)
78+
while (++idx < cnt) {
79+
value_t val = args[idx];
80+
7881
switch (val.type) {
7982
case vt_int:
8083
spec->fldType = key_int;
@@ -97,7 +100,12 @@ value_t fcnIdxInsKey(value_t *args, value_t thisVal, environment_t *env) {
97100

98101
len = keyFld(val, spec, keyValue, index->binaryFlds);
99102
keyValue->keyLen += len;
100-
}
103+
}
104+
else
105+
return s.status = DB_ERROR_badrecid, s;
106+
107+
keyValue->suffixLen =
108+
store64(keyValue->bytes, keyValue->keyLen, docId.idBits);
101109
s.status = insertIdxKey(idxHndl, keyValue);
102110
return s;
103111
}

speed2.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ while(count<1000) {
4545
docIds = store.append(array);
4646

4747
for( idx = 0; idx<1000;idx++)
48-
index.buildKey(docIds[idx], array[idx].doc);
48+
index.insertKey(docIds[idx], array[idx].doc);
4949

5050
// jsdb_commitTxn();
5151
count += 1;
@@ -64,7 +64,7 @@ var reccnt = 0;
6464
var prev = 0;
6565

6666
while( doc = cursor.move(CursorOp.opNext)) {
67-
if (!(reccnt % 998))
67+
if (!(reccnt % 2500))
6868
print("idx: ", reccnt, " docId: ", doc.docId, " key: ", doc.doc);
6969
if (doc.doc < prev)
7070
print ("out of order record #", reccnt, " key: ", doc.doc, " prev: ", prev);

speed3.js

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
var count = 0;
2+
var idx;
3+
4+
var txn;
5+
var start = new Date();
6+
7+
var db, dbname;
8+
9+
for (dbname in catalog.db)
10+
db = new Db(dbname), db.drop();
11+
12+
db = new Db("tstdb", {onDisk:true});
13+
14+
var store = db.createDocStore("collection", {onDisk:true});
15+
var index = store.createIndex("speedIdx", {onDisk:true, idxType:0}, {doc:"fwd:dbl"});
16+
17+
while(count<1000) {
18+
var id, cnt;
19+
idx = 0;
20+
var docIds = [];
21+
22+
// txn = jsdb_beginTxn();
23+
var array = [], key = [];
24+
25+
while(idx<1000) {
26+
// print ("batch: ", count, " item: ", idx);
27+
array[idx] = {
28+
doc : Math.random() * (count * 1000 + idx),
29+
cnt : count,
30+
idx : idx,
31+
/* text0 : "This is a test string designed to make this record bigger0",
32+
text1 : "This is a test string designed to make this record bigger1",
33+
text2 : "This is a test string designed to make this record bigger2",
34+
text3 : "This is a test string designed to make this record bigger3",
35+
text4 : "This is a test string designed to make this record bigger4",
36+
text5 : "This is a test string designed to make this record bigger5",
37+
text6 : "This is a test string designed to make this record bigger6",
38+
text7 : "This is a test string designed to make this record bigger7",
39+
text8 : "This is a test string designed to make this record bigger8",
40+
text9 : "This is a test string designed to make this record bigger9"
41+
*/ };
42+
idx += 1;
43+
}
44+
45+
docIds = store.append(array);
46+
47+
for( idx = 0; idx<1000;idx++)
48+
index.buildKey(docIds[idx], array[idx].doc);
49+
50+
// jsdb_commitTxn();
51+
count += 1;
52+
// print ("batch: ", count);
53+
}
54+
55+
var stop = new Date();
56+
var ins = (stop - start) / 1000.;
57+
start = stop;
58+
59+
var cursor, doc;
60+
61+
cursor = index.createCursor();
62+
63+
var reccnt = 0;
64+
var prev = 0;
65+
66+
while( doc = cursor.move(CursorOp.opNext)) {
67+
if (!(reccnt % 2500))
68+
print("idx: ", reccnt, " docId: ", doc.docId, " key: ", doc.doc);
69+
if (doc.doc < prev)
70+
print ("out of order record #", reccnt, " key: ", doc.doc, " prev: ", prev);
71+
72+
prev = doc.doc;
73+
reccnt += 1;
74+
}
75+
76+
var stop = new Date();
77+
78+
print ("insert: ", ins, " seconds");
79+
print ("found: ", reccnt, " should be 1000000");
80+
print ("sort verify: ", (stop - start) / 1000., " seconds");

0 commit comments

Comments
 (0)