Created
November 22, 2016 18:56
-
-
Save shipilev/e9afaaf8b7b19e26064c01c631154925 to your computer and use it in GitHub Desktop.
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
@BenchmarkMode(Mode.AverageTime) | |
@Warmup(iterations = 5) | |
@Measurement(iterations = 5) | |
@Fork(3) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
@State(Scope.Benchmark) | |
public class MyBenchmark { | |
private static class TestActor extends UntypedActor { | |
@Override | |
public void onReceive(Object message) throws Throwable {} | |
} | |
ActorSystem system; | |
Seq<Object> s; | |
String templateWith3Args; | |
LoggingAdapter adapter; | |
List<String> args; | |
@Setup(Level.Iteration) | |
public void prepare() { | |
system = ActorSystem.apply("test"); | |
args = Arrays.asList("argument1", "argument2", "argument3"); | |
s = scala.collection.JavaConverters.asScalaIteratorConverter(args.iterator()).asScala().toSeq(); | |
templateWith3Args = "{} some text {} another text {} someAnotherText"; | |
adapter = Logging.getLogger(system, system.actorOf(Props.create(TestActor.class))); | |
} | |
@TearDown(Level.Iteration) | |
public void tearDown() { | |
system.terminate(); | |
} | |
@Benchmark | |
public String akkaFormat() { | |
return adapter.format(templateWith3Args, s); | |
} | |
@Benchmark | |
public String simpleFormat() { | |
return new StringBuilder(args.get(0)) | |
.append(" some text ") | |
.append(args.get(1)) | |
.append(" another text ") | |
.append(args.get(2)) | |
.append(" someAnotherText") | |
.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment