Midimaster Active Member Licensed User Jun 25, 2020 #1 I'm still looking for a performant way to load a file with 50.000.000 signed shorts. Now I'm testing loading BYTEs, then coverting it to SHORTs. Trying to convert a big Byte-Array into a big Short Array if the element size is 100.000 the speed is very fast: <10msec if I try to do it with 300.000 elements the time is extremly high >5000msec B4X: Private zeit As Long = DateTime.now Private buffer() As Byte Private Value(2200000) As Short buffer = File.ReadBytes(File.DirAssets,"Myfile.BIN") Log("ZEIT A=" & (DateTime.now-zeit)) Log("BUFFER SIZE= " & buffer.Length) For i= 0 To 300000 'buffer.length/2-2 Value(i)=buffer(2*i+1)*256+buffer(2*i) Next Log("ZEIT B=" & (DateTime.now-zeit)) The loading time is 70msec only, but the converting seems to cause the problem. What ca I do? Some additional Test: if I try this, the time is again >1400msec B4X: ... buffer = File.ReadBytes(File.DirAssets,"ShortExport.MCA") ... Private xxx as Short For i= 0 To 300000 'buffer.length/2-2 Value(i)=0 Next Log("ZEIT B=" & (DateTime.now-zeit)) if I try this, the time is <10msec B4X: ... ... Private xxx as Short For i= 0 To 300000 'buffer.length/2-2 xxx=buffer(0) Next Log("ZEIT B=" & (DateTime.now-zeit)) So it looks like the calculating and the storing are the problems Last edited: Jun 25, 2020
I'm still looking for a performant way to load a file with 50.000.000 signed shorts. Now I'm testing loading BYTEs, then coverting it to SHORTs. Trying to convert a big Byte-Array into a big Short Array if the element size is 100.000 the speed is very fast: <10msec if I try to do it with 300.000 elements the time is extremly high >5000msec B4X: Private zeit As Long = DateTime.now Private buffer() As Byte Private Value(2200000) As Short buffer = File.ReadBytes(File.DirAssets,"Myfile.BIN") Log("ZEIT A=" & (DateTime.now-zeit)) Log("BUFFER SIZE= " & buffer.Length) For i= 0 To 300000 'buffer.length/2-2 Value(i)=buffer(2*i+1)*256+buffer(2*i) Next Log("ZEIT B=" & (DateTime.now-zeit)) The loading time is 70msec only, but the converting seems to cause the problem. What ca I do? Some additional Test: if I try this, the time is again >1400msec B4X: ... buffer = File.ReadBytes(File.DirAssets,"ShortExport.MCA") ... Private xxx as Short For i= 0 To 300000 'buffer.length/2-2 Value(i)=0 Next Log("ZEIT B=" & (DateTime.now-zeit)) if I try this, the time is <10msec B4X: ... ... Private xxx as Short For i= 0 To 300000 'buffer.length/2-2 xxx=buffer(0) Next Log("ZEIT B=" & (DateTime.now-zeit)) So it looks like the calculating and the storing are the problems
Erel B4X founder Staff member Licensed User Longtime User Jun 25, 2020 #2 Are you testing in release mode? Upvote 0
stevel05 Expert Licensed User Longtime User Jun 25, 2020 #3 try the standard Byte Converter library Upvote 0
Midimaster Active Member Licensed User Jun 25, 2020 #4 At the moment I'm testing only in DEBUG mode. Do you expect massiv changes in RELEASE? Where can I change the mode. I'm using B4A Bridge to transfer the app. Upvote 0
At the moment I'm testing only in DEBUG mode. Do you expect massiv changes in RELEASE? Where can I change the mode. I'm using B4A Bridge to transfer the app.
Midimaster Active Member Licensed User Jun 25, 2020 #5 Thanks for the Byte Converter library. This may help!!! Upvote 0
stevel05 Expert Licensed User Longtime User Jun 25, 2020 #6 You can change it in the drop down menu, change it to Release . Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jun 25, 2020 #7 Midimaster said: At the moment I'm testing only in DEBUG mode. Click to expand... Never test performance in debug mode. The numbers are meaningless. Your code is good and it will run very fast. Upvote 0
Midimaster said: At the moment I'm testing only in DEBUG mode. Click to expand... Never test performance in debug mode. The numbers are meaningless. Your code is good and it will run very fast.
OliverA Expert Licensed User Longtime User Jun 25, 2020 #8 Midimaster said: Value(i)=buffer(2*i+1)*256+buffer(2*i) Click to expand... I don't think this is correct, see: Code: Dim bytes(2) As Byte = Array As Byte (-128, -128) Dim value As Short Dim value2 As Short value=bytes(1)*256+bytes(0) Log($"value=${value}"$) value2 = Bit.Or(Bit.ShiftLeft(bytes(1),8), Bit.And(bytes(0), 0xFF)) Log($"value2=${value2}"$) Output: value=32640 value2=-32640 Click to expand... Update: @stevel05's recommendation is best for this scenario (and it also produces -32640) Code: Dim bc As ByteConverter Dim value3() As Short = bc.ShortsFromBytes(bytes) Log($"value3(0)=${value3(0)}"$) Output: value3(0)=-32640 Click to expand... Last edited: Jun 25, 2020 Upvote 0
Midimaster said: Value(i)=buffer(2*i+1)*256+buffer(2*i) Click to expand... I don't think this is correct, see: Code: Dim bytes(2) As Byte = Array As Byte (-128, -128) Dim value As Short Dim value2 As Short value=bytes(1)*256+bytes(0) Log($"value=${value}"$) value2 = Bit.Or(Bit.ShiftLeft(bytes(1),8), Bit.And(bytes(0), 0xFF)) Log($"value2=${value2}"$) Output: value=32640 value2=-32640 Click to expand... Update: @stevel05's recommendation is best for this scenario (and it also produces -32640) Code: Dim bc As ByteConverter Dim value3() As Short = bc.ShortsFromBytes(bytes) Log($"value3(0)=${value3(0)}"$) Output: value3(0)=-32640 Click to expand...
Midimaster Active Member Licensed User Jun 25, 2020 #9 Upps... Bytes in an Byte-Array can have negative values? thank you all. I did not recognize that BYTE() can have negative values. I'm used to old styles BYTES only from 0 to 255. Thank you, then I have to check the data source too! You all help me surviving the first days with this new language. Step by step I'm getting better... Upvote 0
Upps... Bytes in an Byte-Array can have negative values? thank you all. I did not recognize that BYTE() can have negative values. I'm used to old styles BYTES only from 0 to 255. Thank you, then I have to check the data source too! You all help me surviving the first days with this new language. Step by step I'm getting better...
OliverA Expert Licensed User Longtime User Jun 25, 2020 #10 Midimaster said: Upps... Bytes in an Byte-Array can have negative values? Click to expand... It's all up to a programming languages interpretation. B4J/B4A/B4i have only signed bytes. Does not mean that bit-wise a signed byte differs from an unsigned byte, but when it comes to operations performed on them (such as addition an multiplication, even shifting) in B4X, it makes a difference. Upvote 0
Midimaster said: Upps... Bytes in an Byte-Array can have negative values? Click to expand... It's all up to a programming languages interpretation. B4J/B4A/B4i have only signed bytes. Does not mean that bit-wise a signed byte differs from an unsigned byte, but when it comes to operations performed on them (such as addition an multiplication, even shifting) in B4X, it makes a difference.