-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from cozydev-pink/more-benchmarks
Add parser and mapLastTerm benchmarks
- Loading branch information
Showing
2 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
benchmarks/src/main/scala/pink/cozydev/lucille/MapLastTermBenchmark.scala
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,75 @@ | ||
/* | ||
* Copyright 2022 CozyDev | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package pink.cozydev.lucille | ||
package benchmarks | ||
|
||
import java.util.concurrent.TimeUnit | ||
import org.openjdk.jmh.annotations._ | ||
|
||
/** To run the benchmark from within sbt: | ||
* | ||
* jmh:run -i 10 -wi 10 -f 2 -t 1 pink.cozydev.lucille.benchmarks.MapLastTermBenchmark | ||
* | ||
* Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". Please note that | ||
* benchmarks should be usually executed at least in 10 iterations (as a rule of thumb), but | ||
* more is better. | ||
*/ | ||
@State(Scope.Benchmark) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
class MapLastTermBenchmark { | ||
|
||
val rewriteQ = (t: Query.Term) => Query.Or(t, Query.Prefix(t.str)) | ||
|
||
val fullQuery: String = | ||
"this is a long query that will be broken up into one query per character in this string" | ||
val associativityQueryStrings = Vector( | ||
"NOT a AND b", | ||
"a AND NOT b", | ||
"a AND b OR x", | ||
"a AND b OR x AND y", | ||
"a AND b AND c OR x", | ||
"a b AND c", | ||
"a b AND c d", | ||
"a b AND c AND d", | ||
"a b AND c AND d AND e", | ||
"a b AND c AND d OR e", | ||
"a b AND c OR d e", | ||
"a b AND c OR d AND e", | ||
"a b AND c OR d OR e", | ||
) | ||
|
||
var partialQueries: Vector[Query] = _ | ||
var associativityQueries: Vector[Query] = _ | ||
|
||
@Setup | ||
def setup(): Unit = | ||
partialQueries = (1 to fullQuery.size) | ||
.map(fullQuery.take) | ||
.toVector | ||
.map(QueryParser.default.parse) | ||
.map(_.toOption.get) | ||
associativityQueries = associativityQueryStrings.map(QueryParser.parse).map(_.toOption.get) | ||
|
||
@Benchmark | ||
def partialQueriesMapLastTerm(): Unit = | ||
partialQueries.foreach(q => q.mapLastTerm(rewriteQ)) | ||
|
||
@Benchmark | ||
def associativityQueriesMapLastTerm(): Unit = | ||
associativityQueries.foreach(q => q.mapLastTerm(rewriteQ)) | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
benchmarks/src/main/scala/pink/cozydev/lucille/QueryParserBenchmark.scala
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,69 @@ | ||
/* | ||
* Copyright 2022 CozyDev | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package pink.cozydev.lucille | ||
package benchmarks | ||
|
||
import java.util.concurrent.TimeUnit | ||
import org.openjdk.jmh.annotations._ | ||
|
||
/** To run the benchmark from within sbt: | ||
* | ||
* jmh:run -i 10 -wi 10 -f 2 -t 1 pink.cozydev.lucille.benchmarks.QueryParserBenchmark | ||
* | ||
* Which means "10 iterations", "10 warm-up iterations", "2 forks", "1 thread". Please note that | ||
* benchmarks should be usually executed at least in 10 iterations (as a rule of thumb), but | ||
* more is better. | ||
*/ | ||
@State(Scope.Benchmark) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
class QueryParserBenchmark { | ||
|
||
val orQueries10: String = "o 1 2 3 4 5 6 7 8 9" | ||
var orQueries1000: String = _ | ||
val associativityQueries = Vector( | ||
"NOT a AND b", | ||
"a AND NOT b", | ||
"a AND b OR x", | ||
"a AND b OR x AND y", | ||
"a AND b AND c OR x", | ||
"a b AND c", | ||
"a b AND c d", | ||
"a b AND c AND d", | ||
"a b AND c AND d AND e", | ||
"a b AND c AND d OR e", | ||
"a b AND c OR d e", | ||
"a b AND c OR d AND e", | ||
"a b AND c OR d OR e", | ||
) | ||
|
||
@Setup | ||
def setup(): Unit = | ||
orQueries1000 = (1 to 1000).mkString("o ", " ", "") | ||
|
||
@Benchmark | ||
def orQueries10Parse(): Either[String, Query] = | ||
QueryParser.default.parse(orQueries10) | ||
|
||
@Benchmark | ||
def orQueries1000Parse(): Either[String, Query] = | ||
QueryParser.default.parse(orQueries1000) | ||
|
||
@Benchmark | ||
def associativityQueriesParse(): Unit = | ||
associativityQueries.foreach(QueryParser.default.parse) | ||
|
||
} |