Compile times

General FreeBASIC programming questions.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Compile times

Post by jj2007 »

Below a simple 60-lines testbed. Its compile times, in milliseconds:

Code: Select all

300	Gas32: -t 2000 -s console
380	Gcc32: -t 2000 -gen gcc -Wc -O2 -s console
360	Gcc64: -t 2000 -gen gcc -Wc -O2 -s console
300	SARG's version
Same but without the windows and crt includes (they are not necessary here):

Code: Select all

152	gas
230	gcc32
170	gcc64
115	SARG
fbc64_gas64 (20 Nov 2020) barks at me: gcc.exe: error: CreateProcess: No such file or directory

Code: Select all

#include "Windows.bi"	' for e.g. MessageBox(0, "Hello string", "Hello title", MB_OK)
#include "crt.bi"
Print String(20, str("x"))	' String(20, "x") chokes if there is a Utf-8 BOM
Print Left("Добро пожаловать", 5);	' combined output of the three rows:
Print Mid("Добро пожаловать", 6, 5);	' Добро пожалоловать
Print Right("Добро пожаловать", 6)
Print "That was a Russian text printed as Utf8"
Dim MyInt As integer=123456
Dim MyHex As integer=&H1234ABCD
Dim MySingle As Single=123.456
Dim MyDouble As Double=123.456

asm
  #ifdef __FB_64BIT__
	mov rax, [MyHex]
  #else
	mov eax, [MyHex]
  #endif
end asm

' Global variable, visible to main part and procedures
dim shared global as integer=1000

sub foo(number as integer, text as string)
' Local variables visible only inside this procedure
  dim a as integer
  a = global * 3 + number / 2
  print a, text
  global = 555
end sub

' Local variables visible only to main part of FB program
  dim a as integer
  dim s as string

  a = 5
  a = a * 2

  s = "hello"
  s += ", there!"
  print a, s
  
  foo(123, "foo was here")
  foo(-12345, "foo was here again")

  print "MyInt=", MyInt
  print "MySingle=", MySingle
  print "MyDouble=", MyDouble
  print
  if (sizeof(any ptr))=8 Then
	Print "sizes in 64-bit code:"
  else
	Print "sizes in 32-bit code:"
  endif
  Print sizeof(single), "single"
  Print sizeof(double), "double"
  Print sizeof(short), "short"
  Print sizeof(integer), "integer"
  Print sizeof(integer<32>), "integer<32>"
  Print sizeof(integer<64>), "integer<64>"
  Print sizeof(long), "long"
  Print sizeof(longint), "longint"
  Print sizeof(any ptr), "ptr"
  Print "compiled "; Time()

  sleep
Last edited by jj2007 on Dec 10, 2020 15:35, edited 2 times in total.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Compile times

Post by srvaldez »

how are you timing the compile times ?
I use the geany IDE and it doesn't report compile time, I guess that you are using WinFBE
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Compile times

Post by jj2007 »

srvaldez wrote:how are you timing the compile times ?
Timing execution time in a batch file
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Compile times

Post by SARG »

jj2007 wrote:fbc64_gas64 (20 Nov 2020) barks at me: gcc.exe: error: CreateProcess: No such file or directory
No problem on my side. Did you add -gen gas64 ? gcc is not used.

I tried TimeWithAtom but got 2 errors :

Code: Select all

@echo off
TimeWithAtom.exe
set twa=%ERRORLEVEL%
D:\laurent_divers\freebasic64bit\fbc64_gas64 -s console  -RR -R -gen gas64 -v testbed.bas
TimeWithAtom.exe %twa%
pause

Code: Select all

Error in TimeWithAtom: Le nom de sémaphore système spécifié n’a pas été trouvé.  --> system semaphor name not found
FreeBASIC Compiler - Version 1.07.2 (2020-12-08), built for win64 (64bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
standalone
target:       win64, x86-64, 64bit
compiling:    testbed.bas -o testbed.a64 (main module)
assembling:   D:\laurent_divers\freebasic64bit\bin\win64\as.exe --64 --strip-local-absolute "testbed.a64" -o "testbed.o"
linking:      D:\laurent_divers\freebasic64bit\bin\win64\ld.exe -m i386pep -o "testbed.exe" -subsystem console "D:\laurent_divers\freebasic64bit\lib\win64\fbextra.x" --stack 2097152,2097152 -L "D:\laurent_divers\freebasic64bit\lib\win64" -L "." "D:\laurent_divers\freebasic64bit\lib\win64\crt2.o" "D:\laurent_divers\freebasic64bit\lib\win64\crtbegin.o" "D:\laurent_divers\freebasic64bit\lib\win64\fbrt0.o" "testbed.o" "-(" -lkernel32 -lgdi32 -lmsimg32 -luser32 -lversion -ladvapi32 -limm32 -lmsvcrt -lfb -lgcc -lmingw32 -lmingwex -lmoldname -lgcc_eh "-)" "D:\laurent_divers\freebasic64bit\lib\win64\crtend.o"
Error in TimeWithAtom: Descripteur non valide  --> invalid descriptor
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Compile times

Post by jj2007 »

SARG wrote:
jj2007 wrote:fbc64_gas64 (20 Nov 2020) barks at me: gcc.exe: error: CreateProcess: No such file or directory
No problem on my side. Did you add -gen gas64 ? gcc is not used.
That made the trick, thanks. I've added timings for your FB version above - compliments!
I tried TimeWithAtom but got 2 errors : system semaphor name not found
That is unfortunate! It seems the Atom functions don't work on your machine: 187, ERROR_SEM_NOT_FOUND. Which Windows version is yours?
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Compile times

Post by SARG »

jj2007 wrote:That made the trick, thanks. I've added timings for your FB version above - compliments!
Thank you.
jj2007 wrote: Which Windows version is yours?
Windows 10, version 2004. Atom functions need at least W2000 so not the reason.
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Re: Compile times

Post by Landeel »

My current project takes 32 seconds to compile with -gen gcc, and only 1 second with -gen gas:
time fbc32 -gcc gcc -fpu sse -fpmode fast -O max kung04.bas

real 0m30,378s
user 0m32,183s
sys 0m0,594s


time fbc32 -gen gas -fpu sse -fpmode fast -O max kung04.bas

real 0m1,070s
user 0m1,103s
sys 0m0,063s


time fbc -gen gcc -fpu sse -fpmode fast -O max kung04.bas

real 0m25,360s
user 0m26,902s
sys 0m0,492s


time fbc -gen gas64 -fpu sse -fpmode fast -O max kung04.bas

Aborting due to runtime error 12 ("segmentation violation" signal)

fbc32 is the 32-bit compiler renamed, fbc is the 64-bit compiler.

-gen gas64 just crashes.
marcov
Posts: 3454
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Compile times

Post by marcov »

In theory, compiler performance is without externals (GAS/GLD). I also would use sizable sources, since very short sources are more bound by startup/shutdown performance than actual compiling.

In the case of gen gcc it is a bit more complicated, since without gcc the result is less complete than with backend gas. I would time with and without gcc (calling gcc with options to omit assembling/linking), with the without gcc being mostly only to compare with the gas backend to e.g. detect performance problems in the C output writer.

Also should you enable the optimizer for FB when gcc is targeted, or just rely on gcc doing its job? Double optimization could slow down unnecessarily.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Compile times

Post by jj2007 »

SARG wrote:Windows 10, version 2004. Atom functions need at least W2000 so not the reason.
I am still on Win7-64. Now I checked on my wife's Win10 machine, and it fails indeed with that error. This is the very first time that I see an old WinAPI function fail... maybe a safety feature(?)
marcov wrote:In theory, compiler performance is without externals (GAS/GLD)
In practice, it's the whole chain that counts. When I hit the "build" key, I want to see the program running in no time. I get nervous if my sources assemble in more than one second. Building my RichMasm editor (22k lines) takes 1.6 seconds, and that is about the limit for me.
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Compile times

Post by SARG »

jj2007 wrote:I am still on Win7-64. Now I checked on my wife's Win10 machine, and it fails indeed with that error. This is the very first time that I see an old WinAPI function fail...
Sure, that's strange. Have you tried to compile on your wife's PC then run the exe?

Landeel wrote:-gen gas64 just crashes.
Could you try again with removing -fpu sse (not usefull as SSE is used by default but maybe causes the crash) and also -fpmode fast -O max. If It's still crashing I would be interested to see the code.

Edit : I'll test on my side with these options.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Compile times

Post by srvaldez »

timing compile times is not that important to me because most of the time it's less than a second, but I did download Servers
Windows Server 2003 Resource Kit Tools which includes the timeit utility http://web.archive.org/web/201503270141 ... x?id=17657
Landeel
Posts: 777
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Re: Compile times

Post by Landeel »

time fbc32 -gen gas kung04.bas

real 0m1,054s
user 0m1,078s
sys 0m0,085s



time fbc32 -gen gcc kung04.bas

real 0m14,144s
user 0m14,659s
sys 0m0,509s
Without any optimizations. -gen gcc is still much slower (14 seconds vs. 1 second).
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Compile times

Post by srvaldez »

timing compile times is not so simple, it could take over a second the first time but subsequent times take but a fraction of a second, even if you make some small change to the source code
marcov
Posts: 3454
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Compile times

Post by marcov »

jj2007 wrote:In practice, it's the whole chain that counts.
For the user yes. But for the one who has to do optimization, it doesn't really pay off to spend a few months making the compiler 5% faster when it is only 5-10% of the overall performance.
When I hit the "build" key, I want to see the program running in no time. I get nervous if my sources assemble in more than one second. Building my RichMasm editor (22k lines) takes 1.6 seconds, and that is about the limit for me.
Having a target, and how to achieve it are two different things. But anyway, I can strongly recommend to work on an internal assembler and linker for the GAS target. That is probably where the biggest gains are.

Specially since you also like small binaries and need dead code removal (smartlinking) to keep exe sizes somewhat in check. gLD is notoriously slow there on Windows, if it can do it at all.
Last edited by marcov on Dec 10, 2020 19:32, edited 1 time in total.
marcov
Posts: 3454
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Compile times

Post by marcov »

srvaldez wrote:timing compile times is not so simple, it could take over a second the first time but subsequent times take but a fraction of a second, even if you make some small change to the source code
Actually subsequent times often get slower. Because the startup/shutdown and calling external programs (AS/LD) time is divided over less lines compiled.
Post Reply