English 中文(简体)
哪一种描述语言在vs perl vs python vs Mouy中表现得更好? [闭门]
原标题:Which scripting language performs better in vs perl vs python vs ruby? [closed]

Until now, I ve been writing programs in Perl. I decided to give python a try and noticed a few differences. While perl has ARGV, regex, etc. built in, these must be imported in python. I thought this gives python a performance advantage since you re only loading what you really need.

因此,我用每种语文撰写了一个模拟方案,以测试其业绩。

<>Perl

#!/usr/bin/perl

exit(1) if $ARGV[-1] ne  test ;
print "Testing...
";

my $a = 1.0;
my $i;

for (0 .. 500) { $a+=$a/100; }

printf "Result: %.5f
", $a;

<>Python

#!/usr/bin/python

from sys import argv

if argv[-1] !=  test :
   exit(1)

print  Testing... 

a = 1.0
for i in range(0, 501):
    a+=a/100

print  Result: %.5f  %a

<>Ruby>

#!/usr/bin/ruby

if ARGV[0] != "test"
 exit(1)
end

print "Testing...
"
a = 1.0

(0..500).each do a+=a/100 end

printf "Result: %.5f", a

<>C>/strong>

#include <stdio.h>
#include <string.h>

int main (int argc, char *argv[]) {

if (strcmp(argv[1], "test") != 0) return(1);

printf("Testing...
");

double a = 1.0;
int i;

for (i=0; i <= 500; i++)
   a+=a/100;

printf("Result: %.5f
",a);
return 0;
}

The results are:

<>Perl

real 0m0.006s
user 0m0.002s
sys 0m0.004s

<>Python

real 0m0.075s
user 0m0.061s
sys 0m0.013s

<>Ruby>

real 0m0.017s
user 0m0.008s
sys 0m0.008s

<>C>/strong>

real 0m0.003s
user 0m0.001s
sys 0m0.002s

我的检验是否在某种程度上有缺陷?

I ve读到,python更适合大型方案(,见。 当时,这gon是否超过了form。 他们的记忆使用是什么?

我撰写了几份大型申请,作为我的甚高频和高频系统的大标语,而援助团数量有限,因此我的真正目标是尽量减少记忆的使用。

问题回答

有几个问题......

  1. 你的测验没有积累足够的时间,你可能主要测试口译员的开办费用,甚至无法准确衡量。

  2. 如果Perl或Adhur比Rub更快10x,我想使用我认为最佳语言......我最有动机在......时写这句话,我认为这有可能用美丽的文字。

  3. article本条款相当老,当然也包括鲁比。

您对业绩问题没有一般性回答,基准没有多少证明,业绩是一个过于复杂的问题,有待单一标准来判断。 现代化 Perl给你带来了像任何其他体面语言一样的复杂篡改工具,并且非常适合撰写大型方案。

关于记忆效率,你可以说,语言X的这种执行比语言Y的采用少记忆。 但在实践中,我认为,根据你制定和设计的方式,你变式要高得多。 如果你已经用一种语言流利,你或许会更好地利用这种语言,并通过改用另一种语言为你们购买额外记忆。 YMMV。

在阅读评论意见后: 试图通过改写一种不同的语言来减少记忆使用,而不作第一次<>/em>的剖面。

无,这涉及我预期从相对业绩来看这些语言的哪里。

比较彻底的联络处语言,如Sharma和Ruku语,必然会较慢,这二种语言尤其因为它们被解释。 (ok虫可以汇编成册,但其仍然很缓慢)

对大型方案来说,理性基础会更好,因为组织起来比较复杂。 保持大量可调用的相联的手稿,需要大量严格。 特别是在两星期后可以读到时。

多数情况下,规划时间与项目时间同样重要。

我可以考虑的几个问题:

  • 你在浮动号上运作。 你们都知道如何使用每种语言(精确性? 浮动吗? 这可能导致速度/结果差异。

  • 计票数量太小,因此,你应当 do,使方案运作时间超过10次。

例如:

for(0:10000) // change variable depending on what your machine
  for(0:10000)
    // your operation here




相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...