node. JS performance First Glimpse-compute performance (qt/c++,golang,node.js)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Everyone knows that the single-process nonblocking model of node. JS is suitable for task-intensive (I/O) rather than computational-intensive. So how does it fit into the calculation? Let's do a simple test.

The test hardware platform is as follows:

Computer model Apple macmini6,2 Lunch Box
Operating system Windows 8 Enterprise 64-bit (DirectX 11)
Processor Intel third Daicouri I7-3615QM @ 2.30GHz four core
Memory GB (Samsung DDR3 1600MHz)
Primary HDD APPLE HDD hts541010a9e662 (1 TB)


Software platform:

node. js 0.10.21

Qt5.2 Beta1

Golang 1.2 R3


Test method:

Each trip computes Fibonacci 8 times. A total of 10 (altogether 80) times are calculated.

node. JS does not use the cluster module. The test code is as follows:

function Fibo (n) {return n > 1? Fibo (n-1) + Fibo (n-2): 1;} var n = 8;function back () {if (!--N) {return console.timeend (' Total time ');}} Console.time ('total time '), for (var i = 0; i < 8; ++i) {Process.nexttick (function () {Console.log (Fibo (40)); Back ();});
10 times Total Time 132393ms


..... Well, some people would say that there are cluster modules can be processed in multiple processes, and the efficiency will increase. So let's see how it works after using cluster.

Clustervar cluster = require (' cluster '); var numcpus = 8;    My CPU is quad-core eight thread function Fibo (n) {return n > 1? Fibo (n-1) + Fibo (n-2): 1;} Console.time (' 8 cluster '), if (cluster.ismaster) {//Fork workers.for (var i = 0; i < Numcpus; i++) {cluster.fork ();} var i = 8;cluster.on (' Exit ', function (worker, code, signal) {if (!--i) {console.timeend (' 8 cluster ');p rocess.exit (0);}});} else {Console.log (Fibo ());p rocess.exit (0);}

10 times Total Time 30322ms


The following is the same processing (multithreading) done in QT (C + +)

#include <QThread> #include <QDebug> #include <QTime> #include <qtconcurrent>int fibo (int n) { return n > 1? Fibo (n-1) + Fibo (n-2): 1;} int main (int argc, char *argv[]) {qlist<int> lists;for (int i = 0; i < 8; ++i) {lists.append (40);} Qtime Start;start.start (); Qlist<int> thumbnails = qtconcurrent::blockingmapped (lists, Fibo); foreach (int i, thumbnails) {qdebug () << I ;} Qdebug () << "Total time is:  " << start.elapsed ();}
Debug compilation 10 times Total time 14279ms

Release compilation 10 times total time 8280ms


There is also a single thread is doing the same calculation, the code is not affixed to the results of the paste

Debug compilation 10 times total time 64864ms

Release compilation 10 times total time 37790ms


Golang single-threaded code is as follows:

Package Mainimport ("FMT" "Time") func Fibonacci (num int) int {if num < 2 {return 1}return Fibonacci (num-1) + Fibonacci (n UM-2)//I don't remember if Golang has a trinocular operator ...} Func Main () {start: = time. Now () for I: = 0; I < 8; i++ {nums: = Fibonacci (+) fmt. Println (nums)}end: = time. Now () Fmt. PRINTLN ("Total time:", end.) Sub (Start). nanoseconds ()/1000/1000)}
10 times Total time 73910ms.


Golang is calculated using 8 threads:

Package Mainimport ("FMT" "Time" "Runtime") func Fibonacci (num int) int {if num < 2 {return 1}return Fibonacci (num-1) + fi Bonacci (num-2)//I don't remember Golang have a trinocular operator ...} Func main () {ch: = make (chan int, 8) runtime. Gomaxprocs (8) Start: = time. Now () for I: = 0; I < 8; i++ {go func () {nums: = Fibonacci (+) ch <-nums} ()//fmt. Println (nums)}for I: = 0; I < 8; I++{fmt. Println (<-ch)}end: = time. Now () Fmt. PRINTLN ("Total time:", end.) Sub (Start). nanoseconds ()/1000/1000)}
10 times Total Time 14780ms

Detailed test results are as follows:

No cluster 8cluster 8 Thread Debug 8 Thread Release Single Thread Debug Single Thread release Golang Single Thread Golang 8 Threads
13212 3031 1502 847 6538 3804 7413 1443
13253 3029 1429 841 6473 3768 7371 1420
13233 3014 1429 810 6488 3812 7380 1442
13232 3044 1414 811 6467 3757 7420 1545
13465 2980 1466 818 6477 3782 7387 1507
13244 3018 1414 805 6504 3758 7377 1465
13213 3061 1414 831 6461 3771 7373 1494
13192 3025 1402 857 6512 3816 7391 1463
13143 3075 1398 801 6476 3747 7402 1503
13206 3045 1411 859 6468 3775 7396 1498
132393 30322 14279 8280 64864 37790 73910 14780



Look at the data is not very intuitive then look at the following chart ...


Summarize:

We can see the computational performance on C + + > Golang > Node. js.

C + + single core and multithreading efficiency are almost golang one times

Golang single-core and multithreaded performance is almost one-fold of node. js


Written at the end:

This is not a comprehensive authoritative test, the test results only as a reference, does not indicate that node. js efficiency is slag. and node. js I'm also a beginner, the code may be wrong. For test results we should not be too careful, the benevolent see of the beholder.


Go back and run again on my 24-core server to see what happens.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.