06-27-2025, 08:43 AM
Hello,
Excuse me for the poor level of my question, but I'm new to QB64pe.
I'm trying to familiarize myself with the performance of different variable types by creating some simple programs.
I created a program that searches for prime numbers, and I see that my program is three times faster when I don't define the variable type than when I do... Even though I did it to speed up execution!
without DIM: 0.82s
with DIM as _Unsigned Integer: 2.4s
with DIM as Integer: 2.4s
In my program, the values stored in the variables are integers and range from 0 to 14000. So, for me, I had to use INTEGER (only 2 bytes, so fast in my mind).
I just read that when you don't define the variable type, the default is SINGLE (4 bytes).
I wonder why SINGLE is 3 times faster than INTEGER even though it uses 2 times as many bytes?
Excuse me for the poor level of my question, but I'm new to QB64pe.
I'm trying to familiarize myself with the performance of different variable types by creating some simple programs.
I created a program that searches for prime numbers, and I see that my program is three times faster when I don't define the variable type than when I do... Even though I did it to speed up execution!
without DIM: 0.82s
with DIM as _Unsigned Integer: 2.4s
with DIM as Integer: 2.4s
In my program, the values stored in the variables are integers and range from 0 to 14000. So, for me, I had to use INTEGER (only 2 bytes, so fast in my mind).
I just read that when you don't define the variable type, the default is SINGLE (4 bytes).
I wonder why SINGLE is 3 times faster than INTEGER even though it uses 2 times as many bytes?
Code: (Select All)
Dim premier As Single ' SINGLE faster than INTEGER !!! Why ?
Dim chiffreetudie As Single ' SINGLE faster than INTEGER !!! Why ?
Dim diviseur As Single ' SINGLE faster than INTEGER !!! Why ?
T0 = Timer
For chiffreetudie = 2 To 14000
premier = 1
For diviseur = 2 To chiffreetudie - 1
' Print "chiffre etudie = "; chiffreetudie; "Diviseur = "; diviseur; chiffreetudie / diviseur
If chiffreetudie / diviseur = Int(chiffreetudie / diviseur) Then
premier = 0
End If
Next diviseur
If premier = 1 Then
Print chiffreetudie;
End If
Next chiffreetudie
Color 12: Print: Print "Duration : "; Timer - T0; " seconds."


