Constants...
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Skipsy.
Hi folks,
For the time being I am using variables as constantes.
I am not satisfied by this solution because the processor spends
more clock time when accessing to the content of memory address.
For example, in a test :
if x > 100 ; generated code is fast
if x > maximum ; generated code is slower because of the
memory access reading 'maximum'
Is there any way to use real constant ? I mean I 'd like to be able to use a word that will be replace by his value when compiling.
Equivalent of PB constant (#PB_Key...)
Thks a lot.
"If you want to touch the sky,
f**k a duck and try to fly"
Hi folks,
For the time being I am using variables as constantes.
I am not satisfied by this solution because the processor spends
more clock time when accessing to the content of memory address.
For example, in a test :
if x > 100 ; generated code is fast
if x > maximum ; generated code is slower because of the
memory access reading 'maximum'
Is there any way to use real constant ? I mean I 'd like to be able to use a word that will be replace by his value when compiling.
Equivalent of PB constant (#PB_Key...)
Thks a lot.
"If you want to touch the sky,
f**k a duck and try to fly"
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Saboteur.
Really is fast???
Try this:
Result (Athlon 1200, Win98):
Constant time: 3499
Variable time: 3096
Really is fast???
Try this:
Code: Select all
#lim=50
#inc=1
#zer=0
lim=50
inc=1
zer=0
If OpenConsole()
a.l=0
tm1=GetTickCount_()
For f=0 To 500000000
If a<#lim
a+#inc
Else
a=#zer
EndIf
Next f
tm2=GetTickCount_()-tm1
PrintN("Constant time: " + Str(tm2))
tm1=GetTickCount_()
For f=0 To 500000000
If a<lim
a+inc
Else
a=zer
EndIf
Next f
tm2=GetTickCount_()-tm1
PrintN("Variable time: " + Str(tm2))
Input()
EndIf
End
Constant time: 3499
Variable time: 3096
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Berikco.
Constants: 2804
Variables: 3205
P4 1.6GHz XP Pro
Regards,
Berikco
http://users.pandora.be/berikco/purebasic.htm
Constants: 2804
Variables: 3205
P4 1.6GHz XP Pro
Regards,
Berikco
http://users.pandora.be/berikco/purebasic.htm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
constants: 5168
variable: 4556
AMD Duron 800 win2k
seems that the AMD family benefits from using variables instead of constants...
funny thing is that when compiling with /commented switch i get aproximately the opposite result? (i.e. variable = 5150 and constant = 4500, how strange is that?)
constants: 5168
variable: 4556
AMD Duron 800 win2k
seems that the AMD family benefits from using variables instead of constants...
funny thing is that when compiling with /commented switch i get aproximately the opposite result? (i.e. variable = 5150 and constant = 4500, how strange is that?)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by tinman.
The OS speeds may differ when accessing code and data memory?
--
I used to be a nihilist but I don't believe in that any more.
(Win98first ed. + all updates, PB3.62, external editor)
Different sizes of instruction and data caches between manufacturers / families of processors?Originally posted by Pupil
seems that the AMD family benefits from using variables instead of constants...
The OS speeds may differ when accessing code and data memory?
--
I used to be a nihilist but I don't believe in that any more.
(Win98first ed. + all updates, PB3.62, external editor)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Saboteur.
strange
:)
hmmm... without debugger and with /commented, i get same result.constants: 5168
variable: 4556
AMD Duron 800 win2k
seems that the AMD family benefits from using variables instead of constants...
funny thing is that when compiling with /commented switch i get aproximately the opposite result? (i.e. variable = 5150 and constant = 4500, how strange is that?)
strange
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Skipsy.
Wow :
With debugger
Constants: 32797
Variables: 32766
Without debugger :
Constants: 2141
Variables: 2421
(P4 2Ghz 256mo)
To be honest I was considering that loading a registry with a
constant was A LOT faster than accessing to a memory address because
of my experience (a long time ago) with Zilog or 68000 proc.
The difference exists but not so obvious !!!
"If you want to touch the sky,
f**k a duck and try to fly"
Wow :
With debugger
Constants: 32797
Variables: 32766
Without debugger :
Constants: 2141
Variables: 2421
(P4 2Ghz 256mo)
To be honest I was considering that loading a registry with a
constant was A LOT faster than accessing to a memory address because
of my experience (a long time ago) with Zilog or 68000 proc.
The difference exists but not so obvious !!!
"If you want to touch the sky,
f**k a duck and try to fly"
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm