use custom csv writer for performance
This commit is contained in:
@@ -27,10 +27,13 @@ public class Gnuplot {
|
||||
final File gnuplotFile = File.createTempFile("gnuplot", ".dem", tmpDirectory.toFile());
|
||||
Files.write(gnuplotFileContent, gnuplotFile, StandardCharsets.UTF_8);
|
||||
|
||||
final long start = System.nanoTime();
|
||||
|
||||
final ProcessBuilder processBuilder = new ProcessBuilder("gnuplot", gnuplotFile.getAbsolutePath());
|
||||
processBuilder.inheritIO();
|
||||
final Process start = processBuilder.start();
|
||||
start.waitFor();
|
||||
final Process process = processBuilder.start();
|
||||
process.waitFor();
|
||||
|
||||
System.out.println("gnuplot: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package org.lucares.recommind.logs;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@@ -15,10 +18,6 @@ import java.util.stream.Stream;
|
||||
import org.lucares.performance.db.Entry;
|
||||
import org.lucares.performance.db.FileUtils;
|
||||
import org.lucares.performance.db.PerformanceDb;
|
||||
import org.lucares.tanga.svak.StreamSvWriter;
|
||||
import org.lucares.tanga.svak.StreamSvWriterSettings;
|
||||
import org.lucares.tanga.svak.StreamSvWriterSettings.Escaping;
|
||||
import org.lucares.tanga.svak.StreamSvWriterSettings.FieldQuoting;
|
||||
|
||||
public class Plotter {
|
||||
public static void main(final String[] args) throws Exception {
|
||||
@@ -54,11 +53,11 @@ public class Plotter {
|
||||
|
||||
private static void toCsv(final Stream<Entry> entries, final File dataFile) throws IOException {
|
||||
|
||||
final StreamSvWriterSettings svSettings = new StreamSvWriterSettings(",", "'");
|
||||
svSettings.setFieldQuoting(FieldQuoting.IF_NEEDED);
|
||||
svSettings.setEscaping(Escaping.NONE);
|
||||
try (FileOutputStream output = new FileOutputStream(dataFile);
|
||||
StreamSvWriter writer = new StreamSvWriter(output, svSettings)) {
|
||||
final long start = System.nanoTime();
|
||||
int count = 0;
|
||||
final int separator = ',';
|
||||
final int newline = '\n';
|
||||
try (final Writer output = new OutputStreamWriter(new FileOutputStream(dataFile), StandardCharsets.US_ASCII);) {
|
||||
|
||||
final Iterator<Entry> it = entries.iterator();
|
||||
while (it.hasNext()) {
|
||||
@@ -66,8 +65,13 @@ public class Plotter {
|
||||
|
||||
final String value = String.valueOf(entry.getValue());
|
||||
final String date = entry.getDate().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
||||
writer.writeLine(date, value);
|
||||
output.write(date);
|
||||
output.write(separator);
|
||||
output.write(value);
|
||||
output.write(newline);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
System.out.println("wrote " + count + " values to csv in: " + (System.nanoTime() - start) / 1_000_000.0 + "ms");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user