[BENCHMARKS]
* NEW: Do less iterations in benchmarks to get the result faster. * BUG: Fix 'sort.pl' bench. git-svn-id: svn://localhost/gambas/trunk@7438 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
8a0146801b
commit
ebaf5d5ac8
@ -4,28 +4,28 @@ Private Const MAXITER As Integer = 50
|
||||
Private Const LIMIT As Integer = 4
|
||||
|
||||
Sub Mandelbrot(W As Integer, H As Integer)
|
||||
|
||||
|
||||
Dim XMin As Float = -1.5
|
||||
Dim YMin As Float = -1
|
||||
Dim InvN As Float = 2.0 / W
|
||||
Dim CheckNext As Boolean = True
|
||||
Dim X, Y, K As Integer
|
||||
Dim Cr, Ci, Zr, Zi, {Tr}, Ti, T As Float
|
||||
|
||||
|
||||
For Y = 0 To H - 1
|
||||
|
||||
|
||||
Ci = Y * InvN + YMin
|
||||
|
||||
|
||||
For X = 0 To W - 1
|
||||
|
||||
|
||||
Zr = 0
|
||||
Zi = 0
|
||||
{Tr} = 0
|
||||
Ti = 0
|
||||
Cr = X * InvN + XMin
|
||||
|
||||
|
||||
If CheckNext Then
|
||||
|
||||
|
||||
For K = 1 To MAXITER
|
||||
Zi = 2 * Zr * Zi + Ci
|
||||
Zr = {Tr} - Ti + Cr
|
||||
@ -40,38 +40,38 @@ Sub Mandelbrot(W As Integer, H As Integer)
|
||||
Else
|
||||
Print "0";
|
||||
Endif
|
||||
|
||||
|
||||
Else
|
||||
|
||||
|
||||
For K = 1 To MAXITER
|
||||
|
||||
|
||||
Zi = 2 * Zr * Zi + Ci
|
||||
Zr = {Tr} - Ti + Cr
|
||||
Ti = Zi * Zi
|
||||
{Tr} = Zr * Zr
|
||||
|
||||
|
||||
Next
|
||||
|
||||
|
||||
T = {Tr} + Ti
|
||||
If IsNan(T) Or If T > LIMIT Then
|
||||
Print "0";
|
||||
Print "0";
|
||||
CheckNext = True
|
||||
Else
|
||||
Print "1";
|
||||
Endif
|
||||
|
||||
|
||||
Endif
|
||||
|
||||
|
||||
Next
|
||||
|
||||
|
||||
Print
|
||||
|
||||
|
||||
Next
|
||||
|
||||
|
||||
End
|
||||
|
||||
Dim I As Integer
|
||||
|
||||
For I = 1 To 50
|
||||
For I = 1 To 20
|
||||
Mandelbrot(200, 200)
|
||||
Next
|
||||
|
@ -67,9 +67,9 @@ sub mandelbrot($$)
|
||||
}
|
||||
|
||||
print "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(1..50) {
|
||||
for(1..20) {
|
||||
mandelbrot(200, 200);
|
||||
}
|
||||
|
@ -16,13 +16,13 @@ def mandelbrot(w, h) :
|
||||
|
||||
for y in range(h) :
|
||||
Ci = y * invN + ymin
|
||||
|
||||
|
||||
for x in range(w) :
|
||||
Zr = 0.0
|
||||
Zi = 0.0
|
||||
Tr = 0.0
|
||||
Ti = 0.0
|
||||
Cr = x * invN + xmin
|
||||
Cr = x * invN + xmin
|
||||
if (checknext) :
|
||||
for k in range(MAXITER) :
|
||||
Zi = 2 * Zr * Zi + Ci
|
||||
@ -47,8 +47,8 @@ def mandelbrot(w, h) :
|
||||
else :
|
||||
out.write("0")
|
||||
checknext = True
|
||||
|
||||
|
||||
out.write("\n")
|
||||
|
||||
for i in range(50) :
|
||||
for i in range(20) :
|
||||
mandelbrot(200, 200)
|
||||
|
@ -4,7 +4,7 @@ Class Body
|
||||
|
||||
Static Private SOLAR_MASS As Float = 4 * Pi * Pi
|
||||
Private Const DAYS_PER_YEAR As Float = 365.24
|
||||
|
||||
|
||||
Public X As Float
|
||||
Public Y As Float
|
||||
Public Z As Float
|
||||
@ -180,7 +180,7 @@ Class NBodySystem
|
||||
|
||||
Next
|
||||
Next
|
||||
|
||||
|
||||
return E
|
||||
|
||||
End
|
||||
@ -191,7 +191,7 @@ End Class
|
||||
Dim S As New NBodySystem
|
||||
Dim I, N As Integer
|
||||
|
||||
For N = 1 To 10
|
||||
For N = 1 To 5
|
||||
|
||||
Print S.Energy()
|
||||
|
||||
|
@ -20,7 +20,7 @@ sub advance($)
|
||||
{
|
||||
my ($dt) = @_;
|
||||
my ($mm, $mm2, $j, $dx, $dy, $dz, $distance, $mag);
|
||||
|
||||
|
||||
# This is faster in the outer loop...
|
||||
for (0..$last) {
|
||||
# But not in the inner loop. Strange.
|
||||
@ -38,7 +38,7 @@ sub advance($)
|
||||
$vys[$j] += $dy * $mm;
|
||||
$vzs[$_] -= $dz * $mm2;
|
||||
$vzs[$j] += $dz * $mm;
|
||||
}
|
||||
}
|
||||
|
||||
# We're done with planet $_ at this point
|
||||
# This could be done in a seperate loop, but it's slower
|
||||
@ -89,16 +89,16 @@ sub offset_momentum
|
||||
(0, 1.66007664274403694e-03, -2.76742510726862411e-03, 2.96460137564761618e-03, 2.68067772490389322e-03);
|
||||
@vys = map {$_ * DAYS_PER_YEAR}
|
||||
(0, 7.69901118419740425e-03, 4.99852801234917238e-03, 2.37847173959480950e-03, 1.62824170038242295e-03);
|
||||
@vzs = map {$_ * DAYS_PER_YEAR}
|
||||
@vzs = map {$_ * DAYS_PER_YEAR}
|
||||
(0, -6.90460016972063023e-05, 2.30417297573763929e-05, -2.96589568540237556e-05, -9.51592254519715870e-05);
|
||||
@mass = map {$_ * SOLAR_MASS}
|
||||
@mass = map {$_ * SOLAR_MASS}
|
||||
(1, 9.54791938424326609e-04, 2.85885980666130812e-04, 4.36624404335156298e-05, 5.15138902046611451e-05);
|
||||
|
||||
$last = @xs - 1;
|
||||
|
||||
offset_momentum();
|
||||
|
||||
for (1..10)
|
||||
for (1..5)
|
||||
{
|
||||
printf ("%.9f\n", energy());
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
# modified by Maciej Fijalkowski
|
||||
# 2to3
|
||||
|
||||
import sys
|
||||
import sys
|
||||
|
||||
def combinations(l):
|
||||
result = []
|
||||
@ -109,7 +109,7 @@ def offset_momentum(ref, bodies=SYSTEM, px=0.0, py=0.0, pz=0.0):
|
||||
|
||||
def main():
|
||||
offset_momentum(BODIES['sun'])
|
||||
for t in range(10):
|
||||
for t in range(5):
|
||||
report_energy()
|
||||
for n in range(100000):
|
||||
advance(0.01)
|
||||
|
@ -11,7 +11,7 @@ Sub Test(X As Float) As Float
|
||||
|
||||
For I = 0 To N - 1
|
||||
For J = 0 To 99
|
||||
Mu = (Mu + 2.0) / 2.0
|
||||
Mu = Mu / 2 + 1
|
||||
aPoly[J] = Mu
|
||||
Next
|
||||
Su = 0.0
|
||||
@ -27,7 +27,7 @@ End
|
||||
|
||||
Dim I as Integer
|
||||
|
||||
For I = 1 To 4
|
||||
For I = 1 To 2
|
||||
Print Test(0.2)
|
||||
Next
|
||||
|
||||
|
@ -26,10 +26,10 @@ sub poly($)
|
||||
}
|
||||
|
||||
return $pu;
|
||||
}
|
||||
}
|
||||
|
||||
my $res;
|
||||
for (1..4) {
|
||||
for (1..2) {
|
||||
$res = poly(0.2);
|
||||
print "$res\n";
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,6 @@ def t(x):
|
||||
pu = pu + su
|
||||
return pu
|
||||
|
||||
for i in range(0,4):
|
||||
for i in range(2):
|
||||
print t(x)
|
||||
|
||||
|
||||
|
@ -6,10 +6,10 @@ Sub GetPrimes(N As Integer) As Integer[]
|
||||
Dim S As Integer[]
|
||||
Dim I, J, M As Integer
|
||||
Dim iMRoot, iHalf As Integer
|
||||
|
||||
|
||||
If N < 2 Then Return aRes
|
||||
|
||||
If N = 2 Then Return [ 2 ]
|
||||
If N = 2 Then Return [2]
|
||||
|
||||
S = New Integer[(N - 3 + 1) \ 2]
|
||||
For J = 3 To N Step 2
|
||||
@ -18,19 +18,16 @@ Sub GetPrimes(N As Integer) As Integer[]
|
||||
Next
|
||||
|
||||
iMRoot = Sqr(N)
|
||||
iHalf = S.Count
|
||||
iHalf = S.Max
|
||||
I = 0
|
||||
M = 3
|
||||
|
||||
|
||||
While M <= iMRoot
|
||||
|
||||
|
||||
If S[I] Then
|
||||
J = (M * M - 3) \ 2
|
||||
S[J] = 0
|
||||
While J < iHalf
|
||||
S[J] = 0
|
||||
J += M
|
||||
Wend
|
||||
For J = (M * M - 3) \ 2 To iHalf Step M
|
||||
S[J] = 0
|
||||
Next
|
||||
Endif
|
||||
|
||||
Inc I
|
||||
@ -39,8 +36,9 @@ Sub GetPrimes(N As Integer) As Integer[]
|
||||
Wend
|
||||
|
||||
aRes.Add(2)
|
||||
For Each I In S
|
||||
If I Then aRes.Add(I)
|
||||
For I = 0 To S.Max
|
||||
J = S[I]
|
||||
If J Then aRes.Add(J)
|
||||
Next
|
||||
|
||||
Return aRes
|
||||
@ -50,7 +48,7 @@ End
|
||||
Dim aRes As Integer[]
|
||||
Dim I As Integer
|
||||
|
||||
For I = 1 To 10
|
||||
For I = 1 To 5
|
||||
aRes = GetPrimes(10000000)
|
||||
Print aRes.Count
|
||||
Next
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
sub get_primes7($) {
|
||||
my ($n) = @_;
|
||||
|
||||
|
||||
if ($n < 2) { return (); }
|
||||
if ($n == 2) { return (2); }
|
||||
# do only odd numbers starting at 3
|
||||
@ -36,9 +36,9 @@ sub get_primes7($) {
|
||||
}
|
||||
return @res;
|
||||
}
|
||||
|
||||
|
||||
my @res;
|
||||
for (1..10) {
|
||||
for (1..5) {
|
||||
@res = get_primes7(10000000);
|
||||
print scalar @res; print "\n";
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
|
||||
def get_primes7(n):
|
||||
"""
|
||||
standard optimized sieve algorithm to get a list of prime numbers
|
||||
@ -24,7 +24,7 @@ def get_primes7(n):
|
||||
i = i+1
|
||||
m = 2*i+3
|
||||
return [2]+[x for x in s if x]
|
||||
|
||||
for t in range(10):
|
||||
|
||||
for t in range(5):
|
||||
res = get_primes7(10000000)
|
||||
print len(res)
|
@ -4,7 +4,7 @@ Sub BubbleSort(aTab As Integer[])
|
||||
|
||||
Dim N As Integer = aTab.Max
|
||||
Dim I, J As Integer
|
||||
|
||||
|
||||
For I = 0 to N - 1
|
||||
For J = I + 1 To N
|
||||
If aTab[J] < aTab[I] Then
|
||||
@ -12,7 +12,7 @@ Sub BubbleSort(aTab As Integer[])
|
||||
Endif
|
||||
Next
|
||||
Next
|
||||
|
||||
|
||||
End
|
||||
|
||||
Dim I As Integer
|
||||
|
@ -121,7 +121,7 @@ sub bubblesort
|
||||
980,981,421,925,902,880,194,258,918,989,
|
||||
1,991,91,887,607,995,361,350,831,451);
|
||||
|
||||
for (1..1000) {
|
||||
for (1..100) {
|
||||
@tab = @src[0..999];
|
||||
bubblesort(@tab);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user