File: compact_speed_test.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (57 lines) | stat: -rwxr-xr-x 1,321 bytes parent folder | download | duplicates (3)
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
if (1) {

    t = db.compactspeedtest;
    t.drop();

    var obj = { x: 1, y: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", z: [1, 2] };

    var start = new Date();
    function timed() {
        db.getLastError();
        var dt = (new Date()) - start;
        //print("time: " + dt);
        start = new Date();
        return dt;
    }

    //print("adding data");
    var N = 100000;
    if (db.adminCommand("buildInfo").debug)
        N = 10000;
    for (var i = 0; i < N; i++) {
        obj.x = i;
        obj.z[1] = i;
        t.insert(obj);
    }
    var a = timed();

    //print("index");
    t.ensureIndex({ x: 1 });
    //print("index");
    t.ensureIndex({ y: 1 });
    //print("index");
    t.ensureIndex({ z: 1 });

    a += timed();

    //print("count:" + t.count());

    timed();

    {
        //print("compact");
        var res = db.runCommand({ compact: 'compactspeedtest', dev: true });
        b = timed();
        //printjson(res);
        assert(res.ok);

        //print("validate");
        var v = t.validate(true);

        assert(v.ok);
        assert(t.getIndexes().length == 4);
        print("inserting records and adding indexes took " + a);
        print("compact took " + b);
        assert(b < a, "compact was slower than it should be");
    }
}