ITPub博客

首页 > IT职业 > IT职场 > Java, Python, Ruby, PHP, C等语言性能对比

Java, Python, Ruby, PHP, C等语言性能对比

IT职场 作者:sprest 时间:2021-09-09 09:15:38 0 删除 编辑

代码功能:循环拼接字符串,并替换子字符串
硬件环境:Intel Core2 Duo T7500@2.20Ghz CPU; 2 GB RAM; OS Debian GNU/Linux 2.6.32 i686
代码执行时长
代码性能对比图
最慢: Java gcj (native executable)  
较慢: Java (openJDK); Java (Sun); Lua  
稍慢: tcl; Javascript (spidermonkey)  
较快: Python; Ruby; PHP; C++; Javascript V8; C; Perl5  
最快的是Perl,最慢的gcj,你能接受吗?
内存使用情况
内存对比图:
测试源码:
C (source); Result: C gcc (Debian 4.4.4-1) 4.4.4
#include #include #include #include int main(){setbuf(stdout,NULL); //disable output bufferingchar *str=malloc(8);strcpy(str,"abcdefgh");str=realloc(str,strlen(str)+8);strcat(str,"efghefgh");     //sprintf(str,"%s%s",str,"efghefgh");int imax=1024/strlen(str)*1024*4;printf("%s","exec.tm.sectstr.lengthn"); //fflush(stdout);time_t starttime=time(NULL);char *gstr=malloc(0);int i=0;char *pos;int lngth;char *pos_c=gstr;int str_len=strlen(str);

    while(i++ #include #include using namespace std;main (){
  string str = "abcdefgh";
    str += "efghefgh";
  int imax = 1024 /str.length() * 1024 *4;
  time_t currentTime = time(NULL);
  cout 
Python3 (source); Result: Python 3.1.3
#!/usr/bin/python3 -uimport reimport timeimport sysstr='abcdefgh'+'efghefgh'imax=1024/len(str)*1024*4   # 4mbstarttime=time.time();print "exec.tm.sectstr.length"sys.stdout.flush()gstr=''i=0while (i 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3088/viewspace-2801436/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-13

  • 博文量
    101
  • 访问量
    821