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。 他们的记忆使用是什么?
我撰写了几份大型申请,作为我的甚高频和高频系统的大标语,而援助团数量有限,因此我的真正目标是尽量减少记忆的使用。