deno vs node 性能对比

2,023 阅读1分钟
const template = {
  test: 1,
  array: [1, 2, 3, 4, 5, 6],
  array1: [1, 2, 3, 4, 5, 6],
  array2: [1, true, "string", 4, 5, 6],
  array3: [1, 2, 3, 4, 111112312312, 6],
  array4: [1, 2, 3, 4, 5, 6],
  jsonstring: "asflajsdlf;ajsldfjals;djfzxxxslk2.2342",
  jsonstring1: "asflajsdlf;ajsldfjals;djfzxxxslk2.2342",
  jsonstring2: "asflajsdlf;ajsldfjals;djfzxxxslk2.2342",
  jsonstring3: "asflajsdlf;ajsldfjals;djfzxxxslk2.2342",
  jsonstring4: "asflajsdlf;ajsldfjals;djfzxxxslk2.2342",
  jsonstring5: "asflajsdlf;ajsldfjals;djfzxxxslk2.2342",
  jsonstring6: "asflajsdlf;ajsldfjals;djfzxxxslk2.2342",
  jsonstring7: "asflajsdlf;ajsldfjals;djfzxxxslk2.2342",
  a: true,
};

const tempString =
  "sa;lfjasl;fjl;21348lzxcjvlkzjlqjwepruoiuytoiqwyen,xzbcv,zbmxuiwqyerklashdfkla.,czxoupwlqerlas.dfm";
const now = +new Date();
// JSON转换测试
// for (let i = 0; i < 1000000; i++) {
//   JSON.parse(JSON.stringify(template));
// }
// node 1788ms
// deno 1939ms

// 数字计算测试
// for (let i = 0; i < 1000000; i++) {
//   for (let j = 0; j < 10000; j++) {
//     const result = (i + j + j * i + j / i - i) ^ j;
//   }
// }
// node: 8713ms
// deno: 5406ms

// 随机字符串查找
// for (let i = 0; i < 100000000; i++) {
//   const charIndex =
//     Math.floor(Math.random() * tempString.length) % tempString.length;
//   const char = tempString[charIndex];
//   const idx = tempString.indexOf(char);
// }
// node 1362ms
// deno 1369ms

// 斐波那契数列测试
// function fibonacci(n) {
//   if (n == 0) return 0;
//   else if (n == 1) return 1;
//   else return fibonacci(n - 1) + fibonacci(n - 2);
// }

// fibonacci(43);
// node 5770ms
// deno 6214ms
console.log("耗时:", +new Date() - now);

做了以上一些测试案例,发现,deno的性能暂时无法领先node。

仅仅在数学计算的时候有一定优势。

http io 未测试,因为按照文档的说法,是25000,而node是35000,因为node是用c实现了底层。

如果有更好的性能测试对比用例,欢迎大家发出来!!!

另外,在我看来,现在的deno唯一优势就是支持ts。