c, cs, vala 效能簡單測試

來源:互聯網
上載者:User
分別用c, cs 和 vala 完成同樣的運算:Code
#include <stdlib.h>
#include <stdio.h>

int main()
{
  printf("c for begin\n");
  int count = 1000000000;
  int i;
  for(i=0;i<count;i++)
  {
    ;
  }
  printf("c for end\n");

  printf("int add begin\n");
  int ncount = 1000000000;
  int n = 0;
  int j;
  for(j=0;j<ncount;j++)
  {
    int a = 3;
    int b = 4;
    n = a + b;
  }
  printf("%d", n);
  printf("int add end\n");

  printf("float add begin\n");
  int fcount = 10000000;
  float f = 0.0f;
  int k;
  for(k=0;k<fcount;k++)
  {
    float a = 3.0f;
    float b = 4.0f;
    f = a + b;
  }
  printf("%f", f);
  printf("float add end\n");

  return 0; 
}

測試結果:Code
user@mojo:~/Projects/performance/c$ time ./c 
c for begin
c for end
int add begin
7int add end
float add begin
7.000000float add end

real    0m49.264s
user    0m46.450s
sys    0m0.010s

user@mojo:~/Projects/performance/cs$ time mono main.exe
c for begin

c for end

int add begin

7
int add end

float add begin

7
float add end

real    1m37.252s
user    1m31.880s
sys    0m0.135s

user@mojo:~/Projects/performance/vala$ time ./main
c for begin
c for end
int add begin
7int add end
float add begin
7.000000float add end

real    1m14.979s
user    1m10.995s
sys    0m0.020s

ps: 以上測試全部在SmartQ5 (cpu: s3c6410 arm11 667MHz, ram: 128M)上完成, 其間也測試了python和lua,結論是基本上沒有可比性,類死機狀態。

/Files/zhongzf/src.zip

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.