相关疑难解决方法(0)

为什么这个NodeJS比本机C快2倍?

为了在工作中进行演示,我想比较NodeJS和C的性能.这是我写的:

Node.js(for.js):

var d = 0.0,
    start = new Date().getTime();

for (var i = 0; i < 100000000; i++)
{
  d += i >> 1;
}

var end = new Date().getTime();

console.log(d);
console.log(end - start);
Run Code Online (Sandbox Code Playgroud)

C(for.c)

#include <stdio.h>
#include <time.h>

int main () {
  clock_t start = clock();

  long d = 0.0;

  for (long i = 0; i < 100000000; i++)
  {
    d += i >> 1;    
  }

  clock_t end = clock();
  clock_t elapsed = (end - start) / (CLOCKS_PER_SEC …
Run Code Online (Sandbox Code Playgroud)

c optimization performance node.js

9
推荐指数
2
解决办法
5554
查看次数

标签 统计

c ×1

node.js ×1

optimization ×1

performance ×1