[Freebasic 32 vs 64]

General FreeBASIC programming questions.
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Post by Coolman »

FBWin32 fbc -gen gcc -Wc -O2 elapsed time is 50.85937545920933 seconds
FBWin64 fbc -gen gcc -Wc -O2 elapsed time is 39.82537974277511 seconds

No comments
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: [Freebasic 32 vs 64]

Post by srvaldez »

here's an unexpected result, my times are
FBwin32 gas 15.7090276000269 seconds
FBwin32 gcc 9.54091600001459 seconds
FBwin64 gcc 48.57187550002709 seconds
FBdarwin x64 gcc 8.71 seconds

spectral-norm.bas

Code: Select all

/' The Computer Language Benchmarks Game
 '
 ' spectral-norm C gcc #3 program
 ' https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/spectralnorm-gcc-3.html
 '
 ' https://benchmarksgame-team.pages.debian.net/benchmarksgame/
 '
 ' Contributed by Mr Ledrug
 '
 ' https://benchmarksgame-team.pages.debian.net/benchmarksgame/license.html
 '
 ' Algorithm lifted from Intel Fortran #2 code by Steve Decker et al.
 '
 ' FreeBASIC translation by srvaldez with the help of fbfrog https://github.com/dkl/fbfrog
'/

Function A(Byval i As Long, Byval j As Long) As Long
	Return ((((i + j) * ((i + j) + 1)) / 2) + i) + 1
End Function

Function dot(Byval v As Double Ptr, Byval u As Double Ptr, Byval n As Long) As Double
	Dim i As Long
	Dim sum As Double = 0
	For i = 0 To n - 1
		sum += v[i] * u[i]
	Next
	Return sum
End Function

Sub mult_Av(Byval v As Double Ptr, Byval out_ As Double Ptr, Byval n As Const Long)
	Dim i As Long
	Dim j As Long
	Dim sum As Double
	For i = 0 To n - 1
		sum = 0
		For j=0 To n-1
			sum += v[j] / A(i, j)
		Next
		out_[i] = sum
	Next
End Sub

Sub mult_Atv(Byval v As Double Ptr, Byval out_ As Double Ptr, Byval n As Const Long)
	Dim i As Long
	Dim j As Long
	Dim sum As Double
	For i = 0 To n - 1
		sum = 0
		For j=0 To n-1
			sum += v[j] / A(j, i)
		Next
		out_[i] = sum
	Next
End Sub

Dim Shared tmp As Double Ptr

Sub mult_AtAv(Byval v As Double Ptr, Byval out_ As Double Ptr, Byval n As Const Long)
	mult_Av(v, tmp, n)
	mult_Atv(tmp, out_, n)
End Sub

Sub main(Byval n As Long)
	Dim As Double t=Timer
	If n <= 0 Then
		n = 2000
	End If
	Dim u As Double Ptr
	Dim v As Double Ptr
	u = Allocate(n * Sizeof(Double))
	v = Allocate(n * Sizeof(Double))
	tmp = Allocate(n * Sizeof(Double))
	Dim i As Long
	For i = 0 To n - 1
		u[i] = 1
	Next
	For i = 0 To 9
		mult_AtAv(u, v, n)
		mult_AtAv(v, u, n)
	Next
	Print Using "##.#########";Sqr(dot(u, v, n) / dot(v, v, n))
	Print "elapsed time is "; timer-t;" seconds"
	Deallocate(tmp)
	Deallocate(v)
	Deallocate(u)
End Sub

main(5500)
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Post by Coolman »

FBWin32 fbc -gen gcc -Wc -O2 elapsed time is 16.23899118442773 seconds
FBWin64 fbc -gen gcc -Wc -O2 elapsed time is 70.21292596682906 seconds

weird. but with :

FBWin32 fbc fbc -gen gcc -Wc -Ofast elapsed time is 10.25711750597179 seconds
FBWin64 fbc fbc -gen gcc -Wc -Ofast elapsed time is 9.411116133909673 seconds

it is always possible with the gcc build options to optimize programs to the maximum.

with always a slight advantage for the 64 bit.
Post Reply