extract long_to_string converter
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,17 +38,6 @@ public class ScatterPlot implements ConcretePlotter {
|
|||||||
private static final Logger METRICS_LOGGER = LoggerFactory.getLogger("org.lucares.metrics.plotter.scatter");
|
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 PerformanceDb db;
|
||||||
private final Path tmpBaseDir;
|
private final Path tmpBaseDir;
|
||||||
private final Path outputDir;
|
private final Path outputDir;
|
||||||
@@ -200,7 +189,7 @@ public class ScatterPlot implements ConcretePlotter {
|
|||||||
if (fromEpochMilli <= epochMilli && epochMilli <= toEpochMilli) {
|
if (fromEpochMilli <= epochMilli && epochMilli <= toEpochMilli) {
|
||||||
|
|
||||||
long value = entry.getValue();
|
long value = entry.getValue();
|
||||||
final String stringValue = longToString(value);
|
final String stringValue = LongUtils.longToString(value);
|
||||||
final String formattedDate;
|
final String formattedDate;
|
||||||
|
|
||||||
if (useMillis){
|
if (useMillis){
|
||||||
@@ -230,14 +219,4 @@ public class ScatterPlot implements ConcretePlotter {
|
|||||||
return new CsvSummary(dataFile, count, maxValue, aggregator.getAggregatedData());
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user