Test the Mongodb + V8 JavaScript Engine
I know that Mongodb's JavaScript Engine is SpiderMonkey, so I want to compile a v8 version of Mongodb and test it with the following JavaScript file.
Prepare the test code:
Function Dotest (){
Var str = " Xxxxxxxxxxxxxxxxx0000000000 " ;
Var data = Str + Str + Str + Str;
Var data = Data + Data + Data + Data;
Var max = 10000 ;
Var arr = [];
Var total = 0 ;
For (Var = 0 ; < 100 ; ++ ){
For (Var I = 0 ; I
Arr. push (data + " . " + Data );
}
For (Var I = 0 ; I
Total + = Arr [I]. length;
}
Arr = [];
}
Return total;
}
Myecho = (Typeof console! = ' Undefined '& typeof console. log = 'function ')? Console. log: print;
A = New Date ();
Myecho ( " Begin: \ t " + A );
Myecho ( " Result: \ t " + Dotest ());
B = New Date ();
Myecho ( " End: \ t " + B );
Myecho ( " Total time: \ t " + (B - A ));
This JavaScript script can run in four environments at the same time:
Chrome, Firefox, and other browser Environments
Node js shell
Js shell of SpiderMonkey
Mongo js shell
After I have compiled the Mongodb v8 version, I will compare and test the four environments.
Compile mongodb + v8
In OpenSUSE11.4, it is easy to use the linux package management tool to prepare the compiling environment:
# Installed Package: g ++ subversion git python
Sudo zypper install scons tcsh boost - Devel pcre - Devel readline - Devel
Svn checkout http: // V8.googlecode.com / Svn / Trunk / V8
Cd v8
Scons
Cd ..
Git clone git: // Github.com / Mongodb / Mongo. git
Cd sans V8
Scons
# Run mongodb v8
. / Mongod -- Quiet -- Shardsvr -- Dbpath / Home / Dzg / Data / Mongodb / Test / Mongod -- Port 20237 -- Nohttpinterface -- Fork -- Pidfilepath / Home / Dzg / Data / Mongodb / Test / Mongod. pid -- Logpath / Home / Dzg / Log / Mongodb / Test / Mongod. log -- Logappend
Run the test
Execute ~ /Opt/mongov8/mongo localhost: 20237 dotest. js
Mongo + v8: 93 ms
Nodejs: 68 Ms
SpiderMonkey: 442 Ms
Preliminary conclusion:
Mongodb and v8 provide excellent performance, which is close to the execution performance in node. js.
SpiderMonkey 1.9 is five times slower than v8.
Mongodb uses SpiderMonkey, which may be more than 60 times slower than mongodb + v8.
Maybe mongodb's SpiderMonkey version is low? I do not know the exact version of SpiderMonkey IN THE mongodb release.
The js command I tested above SpiderMonkey is from the xulrunner-192.
The test code is short and one-sided. The above performance multiples are only a general estimation, not a comprehensive and accurate evaluation.