|
Post by (X) on Dec 6, 2023 17:05:40 GMT 1
Can you guess what the Debug Output is going to be?
Dim t As Boolean = True Dim f As Boolean = False
Trace Len(t) Trace Len(f) Test Boolean Var Length.G32 (172 B)
|
|
|
Post by Roger Cabo on Dec 6, 2023 17:07:28 GMT 1
I assume byte? but i never use byte or boolean.. always use int for byte and boolean.. From what I think its faster by assembler to get the adresss in 32bits than 8 bits and mask. An perhaps a bit-test should is also slower than memory compare against 4 bytes with test register and branch.. I could be completely wrong!
|
|
|
Post by (X) on Dec 6, 2023 17:09:30 GMT 1
Check this out:
Dim t As Boolean = True Dim f As Boolean = False
Trace Len(t) Trace Len(f)
Type T_Bool tf As Bool EndType
Trace Len(T_Bool)
Dim tf As T_Bool Trace SizeOf(tf)
|
|
|
Post by (X) on Dec 6, 2023 17:24:33 GMT 1
And further:
$Library "gfawinx" $Library "UpdateRT" UpdateRuntime ' Patches GfaWin23.Ocx
Dim t As Boolean = True Dim f As Boolean = False
Trace Len(t) Trace Len(f)
Type T_Bool B0 As Bool B1 As Bool B2 As Bool B3 As Bool B4 As Bool B5 As Bool B6 As Bool B7 As Bool C0 As Bool C1 As Bool C2 As Bool C3 As Bool C4 As Bool C5 As Bool C6 As Bool C7 As Bool EndType
Trace Len(T_Bool)
Dim tf As T_Bool tf.B0 = True tf.B1 = True tf.B2 = True tf.B3 = True tf.B4 = True tf.B5 = True tf.B6 = True tf.B7 = True tf.C0 = True tf.C1 = True tf.C2 = True tf.C3 = True tf.C4 = True tf.C5 = True tf.C6 = True tf.C7 = True Trace tf.B0 Trace tf.B1 Trace tf.B2 Trace tf.B3 Trace tf.B4 Trace tf.B5 Trace tf.B6 Trace tf.B7 Debug HexDump(V:tf) tf.B0 = False tf.B1 = False tf.B2 = False tf.B3 = False tf.B4 = False tf.B5 = False tf.B6 = False tf.B7 = False tf.C0 = False tf.C1 = False tf.C2 = False tf.C3 = False tf.C4 = False tf.C5 = False tf.C6 = False tf.C7 = False Debug HexDump(V:tf) Trace SizeOf(tf) Trace tf.B0 Trace tf.B1 Trace tf.B2 Trace tf.B3 Trace tf.B4 Trace tf.B5 Trace tf.B6 Trace tf.B7
Debug Output...
|
|
|
Post by dragonjim on Dec 6, 2023 18:06:23 GMT 1
Can you guess what the Debug Output is going to be? Dim t As Boolean = True Dim f As Boolean = False
Trace Len(t) Trace Len(f) View AttachmentThe Len function converts the output into a string, with a leading space if it is numeric - interesting that it converts it to " True" and " False" rather than " -1" and " 0". Another interesting thing I noticed when playing around with this is that using Mode StrSpace 0 does not shorten the output as you would expect, although it does for other numeric values: Dim t As Boolean = True Dim f As Boolean = False Dim g As Int32 = 34
Mode StrSpace 1 Trace Len(t) : Trace "*" & t & "*" Trace Len(f) : Trace "*" & f & "*" Trace Len(g) : Trace "*" & g & "*"
Mode StrSpace 0 Trace Len(t) : Trace "*" & t & "*" Trace Len(f) : Trace "*" & f & "*" Trace Len(g) : Trace "*" & g & "*" ...produces... TRACE:(1):Len(t) = 5 TRACE:(2):"*" & t & "*" = * True* TRACE:(3):Len(f) = 6 TRACE:(4):"*" & f & "*" = * False* TRACE:(5):Len(g) = 3 TRACE:(6):"*" & g & "*" = * 34* TRACE:(7):Len(t) = 5 TRACE:(8):"*" & t & "*" = * True* TRACE:(9):Len(f) = 6 TRACE:(10):"*" & f & "*" = * False* TRACE:(11):Len(g) = 2 TRACE:(12):"*" & g & "*" = *34*
|
|
|
Post by dragonjim on Dec 6, 2023 18:18:55 GMT 1
The functions better suited to variable length are SizeOf and BitSizeOf as can be seen from the updated example from the help page:
OpenW 1 Type atest Boolean a - Int b - Double c - Byte d EndType
Dim a As atest a.a = 1 : a.b = 2 : a.c = 3 : a.d = 4
Print " Size of the element in bit" Print "BitSizeOf of a: ", BitSizeOf(a.a) Print "BitSizeOf of b: ", BitSizeOf(a.b) Print "BitSizeOf of c: ", BitSizeOf(a.c) Print "BitSizeOf of d: ", BitSizeOf(a.d) Print Print " Size of the element's in byte" Print "SizeOf of a: ", SizeOf(a.a) Print "SizeOf of b: ", SizeOf(a.b) Print "SizeOf of c: ", SizeOf(a.c) Print "SizeOf of d: ", SizeOf(a.d)
When dealing with user-defined types, Len does work as SizeOf but, as shown in the posts above, when dealing with other types of variables, it converts them into strings first and then outputs the length of the string.
It is similar with Trim: if you use Trim(3), it will automatically convert the number into a string first (with a leading space) then trim it, then output the string version which is "3". So Trim(3) is really Trim(Str(3)), and Len(3) is really Len(Str(3)).
|
|
|
Post by Roger Cabo on Dec 6, 2023 20:26:40 GMT 1
There are also interesting stuff to know about cpus and math. In the past I have tried to optimize sqrt() by a LUT.. or Unity Vector3 trigonometric functions as well. docs.unity3d.com/ScriptReference/Vector3.htmlAll of the functions that use system.math.sqrt() are FASTER than a LUT table. :-) When you tried to optimize the sqrt() function in Unity's Vector3 class using a Lookup Table, you found it slower because accessing memory (to read the LUT) is often slower than calculating the square root directly using SIMD Single Instruction, Multiple Data instructions. Modern CPUs are highly optimized for these calculations, making direct computation faster than memory access in this case. -------- anyway, a setup of the Vector2 functions and methods in gb32 for D2D would be great as lib.. inside of D2D. would be a simple copy and paste. docs.unity3d.com/ScriptReference/Vector2.html (with the source code). Constructors any types as well. it's not much. Types in Double and Single.. (Not sure of someone require single these days, make all the stuff so jerky and unusable in some conditions.) Vector2 Vector2Int Vector4 Quaternion // rotation that would not stuck at 0° Rotation // euler Transform
|
|