Alessandro71 Well-Known Member Licensed User Longtime User May 27, 2026 #1 please, don't mind what the actual code does (nothing) but the proof of concept: is there any performance hit in using method "1"? code sample 1: declaring the ByteConverter locally to the sub that uses it (more readability, all resources used by the sub are local) code sample 2: declaring the ByteConverter once and globally (less readability) local ByteConverter (1) B4X: Copy Public Sub TestSub(data() As Byte) For i = 0 To 1000 ProcessBytes(data) Next End Sub Public Sub ProcessBytes(data() As Byte) Dim bc As ByteConverter Log(bc.HexFromBytes(data)) End Sub global ByteConverter (2) B4X: Copy Sub Class_Globals Dim bc As ByteConverter End Sub Public Sub TestSub(data() As Byte) For i = 0 To 1000 ProcessBytes(data) Next End Sub Public Sub ProcessBytes(data() As Byte) Log(bc.HexFromBytes(data)) End Sub
please, don't mind what the actual code does (nothing) but the proof of concept: is there any performance hit in using method "1"? code sample 1: declaring the ByteConverter locally to the sub that uses it (more readability, all resources used by the sub are local) code sample 2: declaring the ByteConverter once and globally (less readability) local ByteConverter (1) B4X: Copy Public Sub TestSub(data() As Byte) For i = 0 To 1000 ProcessBytes(data) Next End Sub Public Sub ProcessBytes(data() As Byte) Dim bc As ByteConverter Log(bc.HexFromBytes(data)) End Sub global ByteConverter (2) B4X: Copy Sub Class_Globals Dim bc As ByteConverter End Sub Public Sub TestSub(data() As Byte) For i = 0 To 1000 ProcessBytes(data) Next End Sub Public Sub ProcessBytes(data() As Byte) Log(bc.HexFromBytes(data)) End Sub
Erel B4X founder Staff member Licensed User Longtime User May 28, 2026 #2 There is a small overhead involved with the "dimming" of a variable. I don't think that it will be measurable with a 1000 iterations loop (in release mode), though I would have probably used a global variable in this case. Upvote 0
There is a small overhead involved with the "dimming" of a variable. I don't think that it will be measurable with a 1000 iterations loop (in release mode), though I would have probably used a global variable in this case.