Оптимизация преобразования int в hex
Занимаюсь оптимизацией кода. Прошу помощи Я получаю массив (внутри int) на обработку
private void byte_to_hex(byte[] arg1) {
try {
i2 = 0;
while (i2 < arg1.length / 16) {
arg_3 = Arrays.copyOfRange(arg1, i2 * 16, 16 + i2 * 16);
String[] _SS_usb_temp_0 = new String[arg_3.length];
for (int j = 0; j < arg_3.length; j++) {
_SS_usb_temp_0[j] = Int_2_Hex(arg1[j]);
}
_send_ID(_SS_usb_temp_0);
i2 = i2 + 1;
}
} catch (RuntimeException e) {
}
}
да, криво немного, согласен. Но давайте дальше.
public static String Int_2_Hex(int int_value) {
String tt = int_value < 0
? Integer.toHexString(256 + int_value)
: Integer.toHexString(int_value);
if (tt.length() == 1) {
return "0" + tt.toUpperCase();
} else {
return tt.toUpperCase();
}
}
С этим преобразованием загрузка процессора 35% примерно. Но при этом в логах я вижу потерю пакетов
I/sicilla.VestaG: Background concurrent copying GC freed 137445(3MB) AllocSpace objects, 1(20KB) LOS objects, 49% free, 3MB/7MB, paused 343us total 143.127ms
I/sicilla.VestaG: Background concurrent copying GC freed 139013(3MB) AllocSpace objects, 2(40KB) LOS objects, 50% free, 3MB/7MB, paused 5.135ms total 148.789ms
I/sicilla.VestaG: Background concurrent copying GC freed 136877(3MB) AllocSpace objects, 1(20KB) LOS objects, 49% free, 3MB/7MB, paused 325us total 117.309ms
I/sicilla.VestaG: Background concurrent copying GC freed 138396(3MB) AllocSpace objects, 2(40KB) LOS objects, 49% free, 3MB/7MB, paused 361us total 132.995ms
I/sicilla.VestaG: Background concurrent copying GC freed 128695(3MB) AllocSpace objects, 2(40KB) LOS objects, 49% free, 3MB/7MB, paused 93us total 103.841ms
I/sicilla.VestaG: Background concurrent copying GC freed 132061(3MB) AllocSpace objects, 2(40KB) LOS objects, 49% free, 3MB/7MB, paused 205us total 132.478ms
I/sicilla.VestaG: Background concurrent copying GC freed 136010(3MB) AllocSpace objects, 2(40KB) LOS objects, 50% free, 3MB/7MB, paused 314us total 149.794ms
I/sicilla.VestaG: Background concurrent copying GC freed 136929(3MB) AllocSpace objects, 1(20KB) LOS objects, 50% free, 3MB/7MB, paused 325us total 112.468ms
I/sicilla.VestaG: Background concurrent copying GC freed 127767(3MB) AllocSpace objects, 2(40KB) LOS objects, 49% free, 3MB/7MB, paused 317us total 117.676ms
Ок. Я переписываю эту функцию по-другому
public static String Int_2_Hex_2(int int_value) {
if (int_value < 0) {
int_value = 256 + int_value;
}
return String.format("%02X", int_value);
}
Вроде короче. Но при этом загрузка процессора 120%, а потери пакетов почти нет
I/sicilla.VestaG: Background concurrent copying GC freed 184290(4MB) AllocSpace objects, 0(0B) LOS objects, 49% free, 5MB/11MB, paused 293us total 126.500ms
I/sicilla.VestaG: Background concurrent copying GC freed 176036(4MB) AllocSpace objects, 0(0B) LOS objects, 49% free, 5MB/10MB, paused 863us total 126.154ms
I/sicilla.VestaG: Background concurrent copying GC freed 163066(4MB) AllocSpace objects, 1(20KB) LOS objects, 49% free, 5MB/10MB, paused 104us total 143.060ms
I/sicilla.VestaG: Background concurrent copying GC freed 149205(3MB) AllocSpace objects, 0(0B) LOS objects, 50% free, 5MB/10MB, paused 212us total 120.340ms
I/sicilla.VestaG: Background concurrent copying GC freed 168632(4MB) AllocSpace objects, 0(0B) LOS objects, 49% free, 5MB/10MB, paused 204us total 129.314ms
I/sicilla.VestaG: Background concurrent copying GC freed 186139(4MB) AllocSpace objects, 0(0B) LOS objects, 49% free, 4MB/9MB, paused 332us total 122.604ms
I/sicilla.VestaG: Background concurrent copying GC freed 188790(4MB) AllocSpace objects, 1(20KB) LOS objects, 49% free, 4MB/9MB, paused 154us total 122.539ms
Помогите найти золотую середину между загрузкой и потерей пакетов. Оставить преобразование в hex пока нужно, у меня очень большой код обработки сигнала, он на hex ориентирован.