[Gambas-user] Improve a Fast routine
Benoît Minisini
gambas at ...1...
Fri Nov 28 02:04:16 CET 2014
Le 28/11/2014 01:02, martin p cristia a écrit :
> Hi, is there any way to speed up this routine?
> Thanks
>
> Fast Public Function solucionarXgauss(x As Float[], ti As Float[],
> iOrden As Integer) As Integer
> ' OK GAMBAS
>
> Dim c1 As Float
> Dim i As Integer, j As Integer, a As Integer, b As Integer, ok As
> Integer
> Dim l As Integer, h As Integer, i1 As Integer, j1 As Integer
> Dim p1 As Float, iTest As Integer, nTest As Integer
>
> contador = 0
> If iOrden = 0 Then Return 0
> ok = True
>
> 'usa el metodo de Gauss
> 'debe ser cuadrada la matriz
> ' triangulacion
> itest = iorden / 100
>
> For i = 0 To iOrden - 1
>
>
> 'This is to show the progress in the GUI
> FMain.debugInfo("Resolviendo el sistema ", True, Format$(100 *
> i / iorden, "0.00") & "%")
>
> If debanda(i, i) <> 0 Then
> For j = i + 1 To iOrden - 1
> If debanda(j, i) <> 0 Then
> c1 = - debanda(j, i) / debanda(i, i)
> For h = i To iOrden - 1
> addbanda(j, h, c1 * debanda(i, h))
>
> Next
> ti[j] = ti[j] + c1 * ti[i]
> End If
> Next
> Else
> Return
> l = i
> If i = iOrden - 1 Or l > iOrden - 1 Then Return 0 ' el
> sistema es incompatible
>
> Do
> If debanda(l, i) <> 0 Then
> For h = 0 To iOrden - 1
> addbanda(i, h, debanda(l, h))
> Next
> ti[i] = ti[i] + ti[l]
> Exit
> Else
> l = l + 1
> If i = iOrden - 1 Or l > iOrden - 1 Then Return 0 '
> el sistema es incompatible
> End If
> Loop
> End If
>
> Next
> ' sustitucion atrás
>
> x[iOrden - 1] = ti[iOrden - 1] / debanda(iOrden - 1, iOrden - 1)
> For i = iOrden - 2 To 0 Step -1
> p1 = 0
> For j = i + 1 To iOrden - 1
> p1 = p1 - x[j] * debanda(i, j)
>
> Next
> p1 = ti[i] + p1
> x[i] = p1 / debanda(i, i)
> Next
> Return ok
>
> End Function
>
> Fast Public Sub ABanda(ib As Integer, jb As Integer, valor As Float)
>
>
> modCalculus.MatRigEst[ib * modEstru.ordmatrig + jb] = valor
>
> Return
>
>
> End Sub
>
> DeBanda() and AddBanda() are similar
>
Inline the small ABando function, because a function call takes time.
And maybe local variables are faster than global ones, but I'm not sure.
Regards,
--
Benoît Minisini
More information about the User
mailing list