As we all know, Nodejs's single-process non-blocking model is suitable for task-intensive (IO) rather than computing-intensive. How many of them are not suitable for computing? The following is a simple hardware platform for testing: Apple Macmini6 and Windows 8. the single-process non-blocking model of js is suitable for task-intensive (I/O) instead of computing-intensive. so how many are not suitable for computing? The following is 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) intel third generation processor core i7-3615QM @ 2.30 GHz quad core memory 16 GB (Samsung DDR3 1600 MHz) hard drive apple hdd HTS541010A9E662 (1 TB) software platform: Node. js 0.10.21Qt5.2 beta1Golang 1.2 R3 Test method: Calculate Fibonacci eight times each time. total 10 times (80 times in total) total computing time. node. js does not use the cluster module. the test code is as follows: [javascript] function fibo (n) {return n> 1? Fiber (n-1) + fiber (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 total time 132393 ms ..... some people will say that a cluster module can be processed by multiple processes, improving the efficiency. then let's take a look at the effect after using cluster [javascript] // cluster var cluster = require ('cluster'); var numCPUs = 8; // my cpu is a quad-core eight-thread function (n) {return n> 1? Fiber (n-1) + fiber (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'); process. exit (0) ;}}) ;}else {console. log (fibo (40); process. exit (0);} 10 times total time 30322 ms below is the same processing (multithreading) in Qt (C ++) [cpp] # include # Include # Include # Include Int fibo (int n) {return n> 1? Fibo (n-1) + fibo (n-2): 1;} int main (int argc, char * argv []) {QList Lists; for (int I = 0; I <8; ++ I) {lists. append (40);} QTime start; start. start (); QList Thumbnails = QtConcurrent: blockingMapped (lists, fibo); foreach (int I, thumbnails) {qDebug () <I;} qDebug () <"total time is: "<start. elapsed ();} 10 times total time of Debug compilation 14279msRelease 10 times total time of compilation 8280 ms another single thread is also doing the same calculation, the code will not be pasted. Only the result will be posted. the total time for debugging compilation is 64864msRelease. The total time is 10 times. The 37790 ms Golang single-thread code is as follows: [plain] package main import ("fmt" time ") func fibonacci (num int) int {if num <2 {return 1} return fibonacci (num-1) + fibonacci (num-2) // I don't remember whether golang has a three-object operator ......} func main () {start: = time. now () for I: = 0; I <8; I ++ {nums: = maid (40) fmt. println (nums)} end: = time. now () fmt. println ("total time:", end. sub (start ). nanoseconds ()/1000/1000)} ten total time 73910 ms. golang uses 8-thread computing: [cpp] package main import ("fmt" "time" "runtime") func fibonacci (num int) int {if num <2 {return 1} return fibonacci (num-1) + fibonacci (num-2) // I don't remember if golang has a three-object operator ......} func main () {ch: = make (chan int, 8) runtime. GOMAXPROCS (8) start: = time. now () for I: = 0; I <8; I ++ {go func () {nums: = fibonacci (40) 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 Total time 14780 ms detailed test results: no cluster 8 cluster 8 thread Debug 8 thread Release single thread Debug single thread Release Golang single thread Golang 8 thread 13212 3031 1502 847 6538 3804 7413 144313253 3029 1429 841 6473 3768 7371 6488 3812 7380 144213232 3044 1414 811 6467 3757 7420 154513465 2980 1466 818 6477 3782 7387 150713244 3018 1414 805 6504 3758 7377 146513213 3061 1414 831 6461 3771 7373 149413192 3025 1402 857 6512 3816 7391 146313143 3075 1398 801 6476 3747 7402 150313206 3045 1411 859 6468 3775 7396 1498132393 30322 14279 8280 64864 37790 73910 14780
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