理性分析 C++(-O2) 和 JS的性能差距

Test1

#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int t = clock();
  int a = 1000000000,b = 1;
   while(a) {
     b <<= 1;
     a--;
   }
  printf("%d ms\n",clock() - t);
  return 0;
}
// 0 ms
var t;
t = new Date;
var a = 1000000000,
    b = 1;
while(a) {
    b <<= 1;
    a--;
}
console.log(new Date - t + "ms");
// 915ms

Test2

猜你喜欢

转载自www.cnblogs.com/LzyRapx/p/9347580.html