From ebaf5d5ac8e73628943b8f0df8154db63895ca5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sat, 31 Oct 2015 01:02:58 +0000 Subject: [PATCH] [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 --- benchmark/mandelbrot.gbs | 38 +++++++++++++++++++------------------- benchmark/mandelbrot.pl | 4 ++-- benchmark/mandelbrot.py | 8 ++++---- benchmark/nbody.gbs | 6 +++--- benchmark/nbody.pl | 10 +++++----- benchmark/nbody.py | 4 ++-- benchmark/polynom.gbs | 4 ++-- benchmark/polynom.pl | 6 +++--- benchmark/polynom.py | 4 ++-- benchmark/primes.gbs | 26 ++++++++++++-------------- benchmark/primes.pl | 10 +++++----- benchmark/primes.py | 6 +++--- benchmark/sort.gbs | 4 ++-- benchmark/sort.pl | 2 +- 14 files changed, 65 insertions(+), 67 deletions(-) diff --git a/benchmark/mandelbrot.gbs b/benchmark/mandelbrot.gbs index 5128da1a7..4e54ccd5b 100755 --- a/benchmark/mandelbrot.gbs +++ b/benchmark/mandelbrot.gbs @@ -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 diff --git a/benchmark/mandelbrot.pl b/benchmark/mandelbrot.pl index ca1983594..0082d2960 100755 --- a/benchmark/mandelbrot.pl +++ b/benchmark/mandelbrot.pl @@ -67,9 +67,9 @@ sub mandelbrot($$) } print "\n"; - } + } } -for(1..50) { +for(1..20) { mandelbrot(200, 200); } diff --git a/benchmark/mandelbrot.py b/benchmark/mandelbrot.py index 77e4949eb..dbea23d91 100755 --- a/benchmark/mandelbrot.py +++ b/benchmark/mandelbrot.py @@ -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) diff --git a/benchmark/nbody.gbs b/benchmark/nbody.gbs index 0660342a8..edf38c9c4 100755 --- a/benchmark/nbody.gbs +++ b/benchmark/nbody.gbs @@ -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() diff --git a/benchmark/nbody.pl b/benchmark/nbody.pl index c4c3f3ffb..b402cd4e3 100755 --- a/benchmark/nbody.pl +++ b/benchmark/nbody.pl @@ -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()); diff --git a/benchmark/nbody.py b/benchmark/nbody.py index f5924cf8a..a7953e81a 100755 --- a/benchmark/nbody.py +++ b/benchmark/nbody.py @@ -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) diff --git a/benchmark/polynom.gbs b/benchmark/polynom.gbs index 11d5ae9e5..e06b89d76 100755 --- a/benchmark/polynom.gbs +++ b/benchmark/polynom.gbs @@ -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 diff --git a/benchmark/polynom.pl b/benchmark/polynom.pl index 622996619..137a1c65d 100755 --- a/benchmark/polynom.pl +++ b/benchmark/polynom.pl @@ -26,10 +26,10 @@ sub poly($) } return $pu; -} +} my $res; -for (1..4) { +for (1..2) { $res = poly(0.2); print "$res\n"; -} +} diff --git a/benchmark/polynom.py b/benchmark/polynom.py index 35768e235..6b1fabe3f 100755 --- a/benchmark/polynom.py +++ b/benchmark/polynom.py @@ -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) - + diff --git a/benchmark/primes.gbs b/benchmark/primes.gbs index 1cce08fba..bf313ac7c 100755 --- a/benchmark/primes.gbs +++ b/benchmark/primes.gbs @@ -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 diff --git a/benchmark/primes.pl b/benchmark/primes.pl index 84013f0a8..d716e5ad0 100755 --- a/benchmark/primes.pl +++ b/benchmark/primes.pl @@ -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"; -} +} diff --git a/benchmark/primes.py b/benchmark/primes.py index 541b0f86f..0dc4adfe7 100755 --- a/benchmark/primes.py +++ b/benchmark/primes.py @@ -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) \ No newline at end of file diff --git a/benchmark/sort.gbs b/benchmark/sort.gbs index 5c9b976ee..47965c3d3 100644 --- a/benchmark/sort.gbs +++ b/benchmark/sort.gbs @@ -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 diff --git a/benchmark/sort.pl b/benchmark/sort.pl index bc8118db4..d48a4a112 100644 --- a/benchmark/sort.pl +++ b/benchmark/sort.pl @@ -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); }