Skip to content

Commit 1852b27

Browse files
author
Het
committed
resolving comments
1 parent 5e09e06 commit 1852b27

File tree

6 files changed

+126
-21
lines changed

6 files changed

+126
-21
lines changed

build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ dependencies {
4040
implementation 'org.apache.maven:maven-artifact:3.5.2'
4141
implementation 'org.antlr:antlr4-runtime:4.11.1'
4242
implementation 'io.vavr:vavr:0.10.4'
43-
implementation 'org.openjdk.jmh:jmh-core:1.35'
44-
implementation 'org.openjdk.jmh:jmh-generator-annprocess:1.35'
43+
testImplementation 'org.openjdk.jmh:jmh-core:1.35'
44+
testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.35'
4545

46-
compileOnly 'org.projectlombok:lombok:1.18.26'
46+
implementation 'org.projectlombok:lombok:1.18.26'
4747
annotationProcessor 'org.projectlombok:lombok:1.18.26'
48-
annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.36'
48+
testAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.36'
4949

50+
testImplementation 'org.openjdk.jmh:jmh-core:1.35'
51+
testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.35'
5052
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.4.2'
5153
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.4.2'
5254
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.3.3'

src/main/java/com/github/sidhant92/boolparser/application/BoolParserBenchmarkService.java renamed to src/test/java/com/github/sidhant92/boolparser/application/EvaluationBenchmarkService.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
import org.openjdk.jmh.runner.RunnerException;
1616
import org.openjdk.jmh.runner.options.Options;
1717
import org.openjdk.jmh.runner.options.OptionsBuilder;
18-
import com.fasterxml.jackson.core.type.TypeReference;
19-
import com.fasterxml.jackson.databind.ObjectMapper;
2018
import com.github.sidhant92.boolparser.parser.antlr.BoolParser;
19+
import com.github.sidhant92.boolparser.provider.BoolParserDataProvider;
2120
import lombok.SneakyThrows;
2221

2322
/**
@@ -26,19 +25,17 @@
2625
*/
2726
@State (Scope.Benchmark)
2827
@OutputTimeUnit (TimeUnit.MICROSECONDS)
29-
public class BoolParserBenchmarkService {
28+
public class EvaluationBenchmarkService {
3029
private static Map<String, Object> data;
3130

32-
private static String dataString;
33-
3431
private static BoolParser parser;
3532

3633
private static BooleanExpressionEvaluator evaluator;
3734

3835
public static void main(String[] args) throws RunnerException, IOException {
3936

4037
Options opt = new OptionsBuilder()
41-
.include(BoolParserBenchmarkService.class.getSimpleName())
38+
.include(EvaluationBenchmarkService.class.getSimpleName())
4239
.forks(1)
4340
.build();
4441
new Runner(opt).run();
@@ -47,9 +44,7 @@ public static void main(String[] args) throws RunnerException, IOException {
4744
@SneakyThrows
4845
@Setup
4946
public void setup() {
50-
final ObjectMapper objectMapper = new ObjectMapper();
51-
dataString = "{\"b\":1,\"c\":{\"d\":[\"x\",\"y\"],\"e\":\"xyz\"},\"f\":{\"g\":[\"arr1\",\"arr2\"],\"h\":{\"a\":\"b\",\"c\":\"d\",\"e\":true},\"j\":24},\"x\":[\"a1\",\"a2\",\"a3\",\"a4\"],\"y\":24, \"z\": \"c1\"}";
52-
data = objectMapper.readValue(dataString, new TypeReference<Map<String, Object>>() {});
47+
data = BoolParserDataProvider.getData();
5348
parser = new BoolParser();
5449
evaluator = new BooleanExpressionEvaluator(parser);
5550
}
@@ -62,12 +57,4 @@ public void benchmarkEvaluation() {
6257
evaluator.evaluate(rule, data);
6358
}
6459

65-
@Benchmark
66-
@Warmup(iterations = 2)
67-
@BenchmarkMode(Mode.SampleTime) // change here to check for specific mode
68-
public void benchmarkParsing() {
69-
final String rule = "b>0 AND z IN ('c1', 'c2')";
70-
parser.parseExpression(rule);
71-
}
72-
7360
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.github.sidhant92.boolparser.application;
2+
3+
import java.io.IOException;
4+
import java.util.Map;
5+
import java.util.concurrent.TimeUnit;
6+
import org.openjdk.jmh.annotations.Benchmark;
7+
import org.openjdk.jmh.annotations.BenchmarkMode;
8+
import org.openjdk.jmh.annotations.Mode;
9+
import org.openjdk.jmh.annotations.OutputTimeUnit;
10+
import org.openjdk.jmh.annotations.Scope;
11+
import org.openjdk.jmh.annotations.Setup;
12+
import org.openjdk.jmh.annotations.State;
13+
import org.openjdk.jmh.annotations.Warmup;
14+
import org.openjdk.jmh.runner.Runner;
15+
import org.openjdk.jmh.runner.RunnerException;
16+
import org.openjdk.jmh.runner.options.Options;
17+
import org.openjdk.jmh.runner.options.OptionsBuilder;
18+
import com.github.sidhant92.boolparser.parser.antlr.BoolParser;
19+
import com.github.sidhant92.boolparser.provider.BoolParserDataProvider;
20+
import lombok.SneakyThrows;
21+
22+
/**
23+
* @author Het Shah
24+
* @since 09/02/2023
25+
*/
26+
@State (Scope.Benchmark)
27+
@OutputTimeUnit (TimeUnit.MICROSECONDS)
28+
public class ParserBenchmarkService {
29+
private static Map<String, Object> data;
30+
31+
private static BoolParser parser;
32+
33+
34+
public static void main(String[] args) throws RunnerException, IOException {
35+
Options opt = new OptionsBuilder().include(ParserBenchmarkService.class.getSimpleName()).forks(1).build();
36+
new Runner(opt).run();
37+
}
38+
39+
@SneakyThrows
40+
@Setup
41+
public void setup() {
42+
data = BoolParserDataProvider.getData();
43+
parser = new BoolParser();
44+
}
45+
46+
@Benchmark
47+
@Warmup (iterations = 2)
48+
@BenchmarkMode (Mode.SampleTime) //change here to check for specific mode
49+
public void benchmarkEvaluation() {
50+
final String rule = "b>0 AND z IN ('c1', 'c2')";
51+
parser.parseExpression(rule);
52+
}
53+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.github.sidhant92.boolparser.provider;
2+
3+
import java.io.File;
4+
import java.util.Map;
5+
import com.fasterxml.jackson.core.type.TypeReference;
6+
import com.fasterxml.jackson.databind.ObjectMapper;
7+
import io.vavr.control.Try;
8+
9+
/**
10+
* @author Het Shah
11+
* @since 08/02/2023
12+
*/
13+
public class BoolParserDataProvider {
14+
public static Map<String, Object> getData() {
15+
final ObjectMapper objectMapper = CommonsDataProvider.getObjectMapper();
16+
return Try.of(() -> objectMapper.readValue(new File("src/test/resources/data.json"), new TypeReference<Map<String, Object>>() {}))
17+
.getOrElseGet(ex -> null);
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.github.sidhant92.boolparser.provider;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
5+
6+
/**
7+
* @author Het Shah
8+
* @since 08/02/2023
9+
*/
10+
public class CommonsDataProvider {
11+
public static ObjectMapper getObjectMapper() {
12+
return new ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
13+
}
14+
}

src/test/resources/data.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"b":1,
3+
"c":{
4+
"d":[
5+
"x",
6+
"y"
7+
],
8+
"e":"xyz"
9+
},
10+
"f":{
11+
"g":[
12+
"arr1",
13+
"arr2"
14+
],
15+
"h":{
16+
"a":"b",
17+
"c":"d",
18+
"e":true
19+
},
20+
"j":24
21+
},
22+
"x":[
23+
"a1",
24+
"a2",
25+
"a3",
26+
"a4"
27+
],
28+
"y":24,
29+
"z":"c1"
30+
}

0 commit comments

Comments
 (0)