summaryrefslogtreecommitdiff
path: root/jstests/perf/remove1.js
blob: 3e1a1a6b71c0d7ef6f2703df359243010aaa9a22 (plain)
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
/**
 *  Performance tests for removing ojects
 */

var removals = 100;
var size = 500000;
var collection_name = "remove_test";
var msg = "Hello from remove test";

function testSetup(dbConn) {
    var t = dbConn[collection_name];
    t.drop();
    t.ensureIndex( { num : 1 } );

    for (var i=0; i<size; i++){
        t.save({ num : i, msg : msg });
    }
}

function between( low, high, val, msg ) {
    assert( low < val, msg );
    assert( val < high, msg );
}

/**
 *   Compares difference of removing objects from a collection if only includes
 *   field that's indexed, vs w/ additional other fields
 *
 * @param dbConn
 */
function testRemoveWithMultiField(dbConn) {

    var results = {};
    var t = dbConn[collection_name];

    testSetup(dbConn);

    t.remove( {num:0 } );
    results.indexOnly = Date.timeFunc(
        function(){
            for (var i = 1; i < removals; i++) {
                t.remove({num : i});
            }

            t.findOne();
        }
    );

    testSetup(dbConn);
    
    t.remove( {num: 0, msg: msg } );
    results.withAnother = Date.timeFunc(
        function(){
            for (var i = 1; i < removals; i++) {
                t.remove({num : i, msg : msg});
            }

            t.findOne();
        }
    );


    between( 0.65, 1.35, (results.indexOnly / results.withAnother),
            "indexOnly / withAnother (" + results.indexOnly + " / " + results.withAnother + " ) = " +
            results.indexOnly /  results.withAnother + " not in [0.65, 1.35]" );
}

testRemoveWithMultiField(db);