gambas-source-code/benchmark/primes.gbs
gambas 23be942b6a Work continues on the new JIT system.
[BENCHMARKS]
* NEW: Little meaningless changes.

[INTERPRETER]
* NEW: JIT: Support for FOR EACH loops.
* BUG: JIT: Handle function values that are put on stack before calling them.

[COMPILER]
* NEW: JIT: Optimization of mathematic functions.
* NEW: JIT: Support for FOR EACH loops.
* NEW: JIT: Remove successive POP_x() / PUSH_x().
* NEW: JIT: Optimization of DIV and MOD.
* NEW: JIT: Support of internal control local variables used by SELECT and FOR EACH.
* NEW: JIT: Support for SWAP.

[GB.JIT]
* NEW: Optimization of mathematic functions.
* NEW: Variants management.
* NEW: All conversions are handled now.
* NEW: FOR EACH loops are implemented.
2018-06-05 11:43:39 +02:00

59 lines
810 B
Text
Executable file

#!/usr/bin/env gbs3
Sub GetPrimes(N As Integer) As Integer[]
Dim aRes As New 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]
S = New Integer[(N - 3 + 1) \ 2]
For J = 3 To N Step 2
S[I] = J
Inc I
Next
iMRoot = Sqr(N)
iHalf = S.Max
I = 0
M = 3
While M <= iMRoot
If S[I] Then
For J = (M * M - 3) \ 2 To iHalf Step M
S[J] = 0
Next
Endif
Inc I
M = 2 * I + 3
Wend
aRes.Add(2)
For I = 0 To S.Max
J = S[I]
If J Then aRes.Add(J)
Next
Return aRes
End
Dim aRes As Integer[]
Dim I As Integer
dim T as Float = Timer
For I = 1 To 5
aRes = GetPrimes(10000000)
Print aRes.Count
Next
Print Format(Timer - T, "0.000 s")