Skip to content

Commit

Permalink
Merge pull request #386 from OlivierBlanvillain/auto-format
Browse files Browse the repository at this point in the history
Setup automatic code formatter using the Google Java Style
  • Loading branch information
featurecat authored Oct 6, 2018
2 parents d3664d6 + 4315383 commit 4b3e9bf
Show file tree
Hide file tree
Showing 28 changed files with 6,508 additions and 6,310 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
<useFile>false</useFile>
</configuration>
</plugin>
<plugin>
<groupId>com.coveo</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
91 changes: 44 additions & 47 deletions src/main/java/featurecat/benchmark/Stopwatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,55 @@

import java.util.LinkedHashMap;

/**
* Simple stopwatch profiler to benchmark how long code takes to run
*/
/** Simple stopwatch profiler to benchmark how long code takes to run */
public class Stopwatch {
private LinkedHashMap<String, Long> times;
private long startTime;
private long lastTime;
private LinkedHashMap<String, Long> times;
private long startTime;
private long lastTime;

/**
* Begins timing from the moment this object is created.
*/
public Stopwatch() {
times = new LinkedHashMap<>();
startTime = System.nanoTime();
lastTime = startTime;
}
/** Begins timing from the moment this object is created. */
public Stopwatch() {
times = new LinkedHashMap<>();
startTime = System.nanoTime();
lastTime = startTime;
}

/**
* Mark down the current time that it took $marker$ to run.
* @param marker a tag to describe what section of code is being profiled
*/
public void lap(String marker) {
long currentTime = System.nanoTime();
times.put(marker, currentTime - lastTime);
lastTime = currentTime;
}
/**
* Mark down the current time that it took $marker$ to run.
*
* @param marker a tag to describe what section of code is being profiled
*/
public void lap(String marker) {
long currentTime = System.nanoTime();
times.put(marker, currentTime - lastTime);
lastTime = currentTime;
}

/**
* Print the recorded profiler statistics
*/
public void print() {
System.out.println("\n======== profiler ========");
long totalTime = lastTime - startTime;
for (String marker : times.keySet()) {
System.out.printf("%5.1f%% %s\n", 100.0 * times.get(marker) / totalTime, marker);
}
System.out.println("in " + totalTime / 1_000_000.0 + " ms");
/** Print the recorded profiler statistics */
public void print() {
System.out.println("\n======== profiler ========");
long totalTime = lastTime - startTime;
for (String marker : times.keySet()) {
System.out.printf("%5.1f%% %s\n", 100.0 * times.get(marker) / totalTime, marker);
}
System.out.println("in " + totalTime / 1_000_000.0 + " ms");
}

public void printTimePerAction(int numActionsExecuted) {
System.out.println("\n======== profiler ========");
long totalTime = System.nanoTime() - startTime;
System.out.println((totalTime / 1_000_000.0 / numActionsExecuted) + " ms per action");
System.out.println(numActionsExecuted + " total actions executed in " + totalTime / 1_000_000_000.0 + " s");
}
public void printTimePerAction(int numActionsExecuted) {
System.out.println("\n======== profiler ========");
long totalTime = System.nanoTime() - startTime;
System.out.println((totalTime / 1_000_000.0 / numActionsExecuted) + " ms per action");
System.out.println(
numActionsExecuted + " total actions executed in " + totalTime / 1_000_000_000.0 + " s");
}

/**
* Reset the Stopwatch so it can be used again. Begins timing from the moment this method is executed.
*/
public void reset() {
times = new LinkedHashMap<>();
startTime = System.nanoTime();
lastTime = startTime;
}
/**
* Reset the Stopwatch so it can be used again. Begins timing from the moment this method is
* executed.
*/
public void reset() {
times = new LinkedHashMap<>();
startTime = System.nanoTime();
lastTime = startTime;
}
}
Loading

0 comments on commit 4b3e9bf

Please sign in to comment.