extract long_to_string converter

This commit is contained in:
ahr
2018-01-06 08:40:58 +01:00
parent c5c7c03c66
commit 0f2fcc3c9c
2 changed files with 26 additions and 23 deletions

View File

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

View File

@@ -36,18 +36,7 @@ public class ScatterPlot implements ConcretePlotter {
private static final Logger LOGGER = LoggerFactory.getLogger(ScatterPlot.class);
private static final Logger METRICS_LOGGER = LoggerFactory.getLogger("org.lucares.metrics.plotter.scatter");
private static final int INT_TO_STRING_CACHE_SIZE= 1000;
private static final String[] INT_TO_STRING;
static {
INT_TO_STRING = new String[INT_TO_STRING_CACHE_SIZE];
for (int i = 0; i < INT_TO_STRING_CACHE_SIZE; i++){
INT_TO_STRING[i] = String.valueOf(i);
}
}
private final PerformanceDb db;
private final Path tmpBaseDir;
@@ -200,7 +189,7 @@ public class ScatterPlot implements ConcretePlotter {
if (fromEpochMilli <= epochMilli && epochMilli <= toEpochMilli) {
long value = entry.getValue();
final String stringValue = longToString(value);
final String stringValue = LongUtils.longToString(value);
final String formattedDate;
if (useMillis){
@@ -229,15 +218,5 @@ public class ScatterPlot implements ConcretePlotter {
METRICS_LOGGER.debug("wrote {} values to csv in: {}ms (ignored {} values) use millis: {}, grouping={}, file={}", count, (System.nanoTime() - start) / 1_000_000.0, ignoredValues, Boolean.toString(useMillis), groupResult.getGroupedBy(),dataFile);
return new CsvSummary(dataFile, count, maxValue, aggregator.getAggregatedData());
}
private static String longToString(final long value){
// using pre-generated strings reduces memory allocation by up to 25%
if (value < INT_TO_STRING_CACHE_SIZE){
return INT_TO_STRING[(int) value];
}
return String.valueOf(value);
}
}