-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
benchmarks/src/main/java/com/google/re2j/benchmark/BenchmarkSplit.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,45 @@ | ||
/* | ||
* Copyright (c) 2021 The Go Authors. All rights reserved. | ||
* | ||
* Use of this source code is governed by a BSD-style | ||
* license that can be found in the LICENSE file. | ||
*/ | ||
package com.google.re2j.benchmark; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
@State(Scope.Benchmark) | ||
public class BenchmarkSplit { | ||
@Param({"JDK", "RE2J"}) | ||
private Implementations impl; | ||
|
||
private Implementations.Pattern pattern; | ||
|
||
private String input; | ||
|
||
@Setup | ||
public void setup() { | ||
pattern = Implementations.Pattern.compile(impl, "a"); | ||
|
||
StringBuilder b = new StringBuilder(); | ||
for (int i = 0; i < 100; i++) { | ||
b.append("this should be a pretty big string containing a few delimiters to split on"); | ||
} | ||
|
||
input = b.toString(); | ||
} | ||
|
||
@Benchmark | ||
public void benchmarkSplit(Blackhole bh) { | ||
bh.consume(pattern.split(input)); | ||
} | ||
} |
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