Polynom
This benchmark computes a 100-term polynom 500000 times. It is repeated ten times.
Results
The execution time is the user time added to the system time, as returned by the bash "time" command.
|
|
Python
|
Perl
|
Gambas
|
Gambas + JIT
|
|
Execution time (s)
|
133
|
319
|
100
|
9.2
|
|
vs. Python
|
1
|
2.39
|
0.75
|
0.07
|
|
vs. Perl
|
0.42
|
1
|
0.31
|
0.03
|
|
vs. Gambas
|
1.33
|
3.18
|
1
|
0.09
|
|
vs. Gambas + JIT
|
14.46
|
34.67
|
10.87
|
1
|
Python source code
#!/usr/bin/python
n = 500000
x = 0.2
def t(x):
mu = 10.0
pu = 0.0
pol = [0] * 100
r = range(0,100)
for i in range(0,n):
for j in r:
pol[j] = mu = (mu + 2.0) / 2.0
su = 0.0
for j in r:
su = x * su + pol[j]
pu = pu + su
return pu
for i in range(0,10):
print t(x)
Perl source code
#!/usr/bin/perl -w
use strict;
sub poly($)
{
my $n = 500000;
my $x = $_[0];
my $mu = 10;
my $pu = 0;
my @pol;
foreach (0 .. $n - 1) {
foreach (0 .. 99) {
$pol[$_] = $mu = ($mu + 2) / 2;
}
my $s = 0;
foreach (0 .. 99) {
$s = $x * $s + $pol[$_];
}
$pu += $s;
}
return $pu;
}
my $res;
for (1..10) {
$res = poly(0.2);
print "$res\n";
}
Gambas source code
#!/usr/bin/env gbs3
Sub Test(X As Float) As Float
Dim Mu As Float = 10.0
Dim Pu, Su As Float
Dim I, J, N As Integer
Dim aPoly As New Float[100]
N = 500000
For I = 0 To N - 1
For J = 0 To 99
Mu = (Mu + 2.0) / 2.0
aPoly[J] = Mu
Next
Su = 0.0
For J = 0 To 99
Su = X * Su + aPoly[J]
Next
Pu += Su
Next
Return Pu
End
Dim I as Integer
For I = 1 To 10
Print Test(0.2)
Next