Last active
August 29, 2015 14:20
-
-
Save ktoso/0fcac046208dbc3dec6e to your computer and use it in GitHub Desktop.
ProcessBuilder showdown!
This file contains hidden or 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
/* | |
* Copyright (C) 2015 Typesafe Inc. <http://www.typesafe.com> | |
*/ | |
package akka.benchmarks | |
import java.util.concurrent.TimeUnit | |
import org.openjdk.jmh.annotations._ | |
/* | |
This benchmark can be run using https://github.com/ktoso/sbt-jmh | |
[info] Benchmark Mode Cnt Score Error Units | |
[info] ProcessBenchmark.java_pb_create avgt 20 1.683 ± 0.017 ms/op | |
[info] ProcessBenchmark.scala_pb_create avgt 20 2.018 ± 0.109 ms/op | |
[info] ProcessBenchmark.java_pb_wait avgt 20 4.046 ± 0.148 ms/op | |
[info] ProcessBenchmark.scala_pb_wait avgt 20 4.169 ± 0.263 ms/op | |
*/ | |
@State(Scope.Benchmark) | |
@BenchmarkMode(Array(Mode.AverageTime)) | |
@OutputTimeUnit(TimeUnit.MICROSECONDS) | |
class ProcessBenchmark { | |
implicit val system = ActorSystem("test") | |
@TearDown | |
def shutdown() { | |
system.shutdown() | |
system.awaitTermination() | |
} | |
@Benchmark | |
def java_pb_wait(): Int = { | |
new java.lang.ProcessBuilder("ls").start().waitFor() | |
} | |
@Benchmark | |
def scala_pb_wait(): Int = { | |
import scala.sys.process._ | |
"""ls""".!(ProcessLogger(_ ⇒ (), _ ⇒ ())) | |
} | |
@Benchmark | |
def java_pb_create(): Process = { | |
new java.lang.ProcessBuilder("ls").start() | |
} | |
@Benchmark | |
def scala_pb_create(): scala.sys.process.Process = { | |
import scala.sys.process._ | |
"""ls""".run(ProcessLogger(_ ⇒ (), _ ⇒ ())) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment