Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code optimized and created a reusable method to get writer output #4750

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/jmh/java/org/jabref/benchmarks/Benchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,22 @@ public void init() throws Exception {
entry.setField("rnd", "2" + randomizer.nextInt());
database.insertEntry(entry);
}
StringWriter outputWriter = new StringWriter();
BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(outputWriter, mock(SavePreferences.class));
databaseWriter.savePartOfDatabase(
new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries());
bibtexString = outputWriter.toString();

bibtexString = getOutputWriter().toString();

latexConversionString = "{A} \\textbf{bold} approach {\\it to} ${{\\Sigma}}{\\Delta}$ modulator \\textsuperscript{2} \\$";

htmlConversionString = "<b>&Ouml;sterreich</b> &#8211; &amp; characters &#x2aa2; <i>italic</i>";
}

private StringWriter getOutputWriter() throws IOException {
StringWriter outputWriter = new StringWriter();
BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(outputWriter, mock(SavePreferences.class));
databaseWriter.savePartOfDatabase(
new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries());
return outputWriter;
}

@Benchmark
public ParserResult parse() throws IOException {
BibtexParser parser = new BibtexParser(Globals.prefs.getImportFormatPreferences(), new DummyFileUpdateMonitor());
Expand All @@ -81,10 +86,7 @@ public ParserResult parse() throws IOException {

@Benchmark
public String write() throws Exception {
StringWriter outputWriter = new StringWriter();
BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(outputWriter, mock(SavePreferences.class));
databaseWriter.savePartOfDatabase(new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries());
return outputWriter.toString();
return getOutputWriter().toString();
}

@Benchmark
Expand Down