-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve performance of
WinProcess#getEnvironmentVariables
(#69)
- Loading branch information
Showing
6 changed files
with
159 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public class BenchmarkRunner { | ||
|
||
public static void main(String[] args) throws Exception { | ||
org.openjdk.jmh.Main.main(args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/test/java/org/jvnet/winp/ProcessEnvironmentVariableBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jvnet.winp; | ||
|
||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
import java.util.Map; | ||
import java.util.TreeMap; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class ProcessEnvironmentVariableBenchmark { | ||
|
||
@Benchmark | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@Fork(1) | ||
public void testEnvRetreival(ProcessState state, Blackhole blackhole) { | ||
WinProcess wp = new WinProcess(state.p); | ||
Map<String, String> env = wp.getEnvironmentVariables(); | ||
//System.out.println(env.get("USERNAME")); | ||
blackhole.consume(env); | ||
} | ||
|
||
@Benchmark | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@Fork(1) | ||
public void testNativeRaw(ProcessState state, Blackhole blackhole) { | ||
WinProcess wp = new WinProcess(state.p); | ||
String str = Native.getCmdLineAndEnvVars(wp.getPid()); | ||
blackhole.consume(str); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.jvnet.winp; | ||
|
||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.TearDown; | ||
import org.openjdk.jmh.annotations.State; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
@State(Scope.Benchmark) | ||
public class ProcessState { | ||
|
||
private static final File NULL_FILE = new File("NUL:"); | ||
|
||
public Process p; | ||
|
||
@Setup(Level.Trial) | ||
public void setUp() throws IOException { | ||
ProcessBuilder pb = new ProcessBuilder(); | ||
pb.command("ping", "-t", "localhost"); | ||
pb.redirectError(NULL_FILE); | ||
pb.redirectOutput(NULL_FILE); | ||
p = pb.start(); | ||
} | ||
|
||
@TearDown(Level.Trial) | ||
public void tearDown() throws InterruptedException { | ||
p.destroyForcibly(); | ||
p.waitFor(); | ||
} | ||
} |