increase cache of stringified longs

This should improve the csv generation a little bit.
This commit is contained in:
2019-05-25 17:55:14 +02:00
parent 1be57dce0c
commit 4f57a29c3b

View File

@@ -2,21 +2,21 @@ package org.lucares.recommind.logs;
public class LongUtils { public class LongUtils {
private static final int INT_TO_STRING_CACHE_SIZE= 1000; private static final int INT_TO_STRING_CACHE_SIZE = 10_000;
private static final String[] INT_TO_STRING; private static final String[] INT_TO_STRING;
static { static {
INT_TO_STRING = new String[INT_TO_STRING_CACHE_SIZE]; INT_TO_STRING = new String[INT_TO_STRING_CACHE_SIZE];
for (int i = 0; i < INT_TO_STRING_CACHE_SIZE; i++){ for (int i = 0; i < INT_TO_STRING_CACHE_SIZE; i++) {
INT_TO_STRING[i] = String.valueOf(i); INT_TO_STRING[i] = String.valueOf(i);
} }
} }
public static String longToString(final long value){ public static String longToString(final long value) {
// using pre-generated strings reduces memory allocation by up to 25% // using pre-generated strings reduces memory allocation by up to 25%
if (value < INT_TO_STRING_CACHE_SIZE){ if (value < INT_TO_STRING_CACHE_SIZE) {
return INT_TO_STRING[(int) value]; return INT_TO_STRING[(int) value];
} }
return String.valueOf(value); return String.valueOf(value);