Permalink
Browse files

RAND_INT takes a multiplier

  • Loading branch information...
1 parent 4e1c66f commit f3744095b94d264ad83a11d0eb0faea2862f01eb @erh erh committed Mar 13, 2012
Showing with 31 additions and 0 deletions.
  1. +27 −0 jstests/bench_test3.js
  2. +4 −0 src/mongo/scripting/bench.cpp
@@ -0,0 +1,27 @@
+t = db.bench_test3
+t.drop();
+
+
+benchArgs = { ops : [ { ns : t.getFullName() ,
+ op : "update" ,
+ upsert : true ,
+ query : { _id : { "#RAND_INT" : [ 0 , 5 , 4 ] } } ,
+ update : { $inc : { x : 1 } } } ] ,
+ parallel : 2 ,
+ seconds : 1 ,
+ totals : true ,
+ host : db.getMongo().host }
+
+if (jsTest.options().auth) {
+ benchArgs['db'] = 'admin';
+ benchArgs['username'] = jsTest.options().adminUser;
+ benchArgs['password'] = jsTest.options().adminPassword;
+}
+
+res = benchRun( benchArgs )
+printjson( res );
+
+var keys = []
+var totals = {}
+db.bench_test3.find().sort( { _id : 1 } ).forEach( function(z){ keys.push( z._id ); totals[z._id] = z.x } );
+assert.eq( [ 0 , 4 , 8 , 12 , 16 ] , keys )
@@ -133,6 +133,10 @@ namespace mongo {
int max = i.next().numberInt();
int x = min + ( rand() % ( max - min ) );
+
+ if ( i.more() )
+ x *= i.next().numberInt();
+
b.append( e.fieldName() , x );
}
else {

0 comments on commit f374409

Please sign in to comment.