diff options
author | Aaron <aaron@10gen.com> | 2009-01-27 14:31:40 -0500 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2009-01-27 14:31:40 -0500 |
commit | 9436315b03885ce6a93d8ca1922ed2be92e3341f (patch) | |
tree | 0dbdde5bf7a9f9dae4ecd0cb0a767d9d3e331ba2 /jstests/perf | |
parent | 32d9139936d367a491443b7fec33ca9924dfdbdb (diff) | |
download | mongo-9436315b03885ce6a93d8ca1922ed2be92e3341f.tar.gz |
Move over find1.js performance test
Diffstat (limited to 'jstests/perf')
-rw-r--r-- | jstests/perf/find1.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/jstests/perf/find1.js b/jstests/perf/find1.js new file mode 100644 index 00000000000..59f53296893 --- /dev/null +++ b/jstests/perf/find1.js @@ -0,0 +1,78 @@ +/** + * Performance tests for various finders + */ + +var calls = 100; +var size = 500000; +var collection_name = "sort2"; + +function testSetup(dbConn) { + var t = dbConn[collection_name]; + t.drop(); + + for (var i=0; i<size; i++){ + t.save({ num : i }); + if (i == 0 ) + t.ensureIndex( { num : 1 } ); + } +} + +/** + * Tests fetching a set of 10 objects in sorted order, comparing getting + * from front of collection vs end, using $lt + */ +function testFindLTFrontBack(dbConn) { + + var results = {}; + var t = dbConn[collection_name]; + + results.oneInOrderLTFirst = Date.timeFunc( + function(){ + assert( t.find( { num : {$lt : 20} } ).sort( { num : 1 } ).limit(10).toArray().length == 10); + } , calls ); + + results.oneInOrderLTLast = Date.timeFunc( + function(){ + assert( t.find( { num : {$lt : size-20 }} ).sort( { num : 1 } ).limit(10).toArray().length == 10); + } , calls ); + + + assert( 0.9 < (results.oneInOrderLTFirst / results.oneInOrderLTLast) < 1.1, + "first / last (" + results.oneInOrderLTFirst + " / " + results.oneInOrderLTLast + " ) = " + + results.oneInOrderLTFirst / results.oneInOrderLTLast + " not in [0.9, 1.1]" ); +} + + + +/** + * Tests fetching a set of 10 objects in sorted order, comparing getting + * from front of collection vs end + */ +function testFindGTFrontBack(dbConn) { + + var results = {}; + var t = dbConn[collection_name]; + + results.oneInOrderGTFirst = Date.timeFunc( + function(){ + assert( t.find( { num : {$gt : 5} } ).sort( { num : 1 } ).limit(10).toArray().length == 10); + } , calls ); + + results.oneInOrderGTLast = Date.timeFunc( + function(){ + assert( t.find( { num : {$gt : size-20 }} ).sort( { num : 1 } ).limit(10).toArray().length == 10); + } , calls ); + + + assert( 0.25 < (results.oneInOrderGTFirst / results.oneInOrderGTLast) < 4.0, + "first / last (" + results.oneInOrderGTFirst + " / " + results.oneInOrderGTLast + " ) = " + + results.oneInOrderGTFirst / results.oneInOrderGTLast + " not in [0.25, 4.0]" ); + +} + +var db = connect( "ed_perf_find_tests" ); + +testSetup(db); + +testFindLTFrontBack(db); +testFindGTFrontBack(db);
\ No newline at end of file |