Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module rearange and add kotlin benchmark #950

Merged
merged 16 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ jobs:
uses: gradle/gradle-build-action@v2.4.2
with:
arguments: jmh
- name: Read benchmark result
- name: Merge benchmark results
id: merge
run: |
echo "" > merged_results.csv
find ./fixture-monkey-benchmarks -name 'results.csv' | while read line; do
cat "$line" >> merged_results.csv
echo "" >> merged_results.csv
done
cat merged_results.csv
- name: Read merged benchmark result
id: csv
uses: juliangruber/read-file-action@v1
with:
path: ./fixture-monkey/build/results/jmh/results.csv
path: merged_results.csv
- name: Create Markdown table
uses: petems/csv-to-md-table-action@master
id: csv-table-output
Expand Down
31 changes: 31 additions & 0 deletions fixture-monkey-benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id("me.champeau.jmh") version "0.7.2"
`java-test-fixtures`
}

tasks.jmh{
enabled = false
}

subprojects {
tasks.filter { it.name != "jmh" && !it.name.startsWith("compile") && it.name != "jar" }
.forEach { it.enabled = false }

plugins.apply("me.champeau.jmh")
plugins.apply("java-test-fixtures")

dependencies {
jmhImplementation(project(":fixture-monkey-javax-validation"))
jmhImplementation(project(":fixture-monkey-jackson"))
jmhImplementation("org.openjdk.jmh:jmh-core:${Versions.JMH}")
jmhImplementation("org.openjdk.jmh:jmh-generator-annprocess:${Versions.JMH}")
jmhImplementation("org.projectlombok:lombok:${Versions.LOMBOK}")
jmhAnnotationProcessor("org.projectlombok:lombok:${Versions.LOMBOK}")

testFixturesApi(project(":fixture-monkey-javax-validation"))
testFixturesApi("org.openjdk.jmh:jmh-core:${Versions.JMH}")
testFixturesApi("org.openjdk.jmh:jmh-generator-annprocess:${Versions.JMH}")
testFixturesApi("org.projectlombok:lombok:${Versions.LOMBOK}")
testFixturesAnnotationProcessor("org.projectlombok:lombok:${Versions.LOMBOK}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
id("org.jetbrains.kotlin.jvm") version Versions.KOTLIN
id("org.jlleitschuh.gradle.ktlint") version Versions.KTLINT
id("com.navercorp.fixturemonkey.gradle.plugin.maven-publish-conventions")
}

dependencies {
api(project(":fixture-monkey-kotlin"))
jmhImplementation(testFixtures(project(":fixture-monkey-benchmarks:fixture-monkey-benchmark")))
}

jmh {
fork = 1
warmupIterations = 3
iterations = 10
resultFormat = "CSV"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.navercorp.fixturemonkey.kotlin

import com.navercorp.fixturemonkey.OrderSheet
import com.navercorp.fixturemonkey.FixtureMonkey
import com.navercorp.fixturemonkey.api.introspector.BeanArbitraryIntrospector
import com.navercorp.fixturemonkey.api.type.TypeCache
import java.util.concurrent.TimeUnit
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.BenchmarkMode
import org.openjdk.jmh.annotations.Level
import org.openjdk.jmh.annotations.Mode
import org.openjdk.jmh.annotations.OutputTimeUnit
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.Setup
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.infra.Blackhole

private const val COUNT = 500

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
open class KotlinObjectGenerationBenchMark {
@Setup(value = Level.Iteration)
fun setUp() {
TypeCache.clearCache()
}

@Benchmark
fun beanGenerateJavaOrderSheetWithFixtureMonkey(blackhole: Blackhole) {
val fixtureMonkey = FixtureMonkey.builder()
.plugin(KotlinPlugin())
.objectIntrospector(BeanArbitraryIntrospector.INSTANCE)
.build()
blackhole.consume(generateJavaOrderSheet(fixtureMonkey))
}

private fun generateJavaOrderSheet(fixtureMonkey: FixtureMonkey): List<OrderSheet> =
List(COUNT) { fixtureMonkey.giveMeOne(OrderSheet::class.java) }

@Benchmark
fun beanGenerateKotlinOrderSheetWithFixtureMonkey(blackhole: Blackhole) {
val fixtureMonkey = FixtureMonkey.builder()
.plugin(KotlinPlugin())
.build()
blackhole.consume(generateKotlinOrderSheet(fixtureMonkey))
}

private fun generateKotlinOrderSheet(fixtureMonkey: FixtureMonkey): List<KotlinOrderSheet> =
List(COUNT) { fixtureMonkey.giveMeOne(KotlinOrderSheet::class.java) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.navercorp.fixturemonkey.kotlin

import java.math.BigDecimal
import java.time.Instant
import javax.validation.constraints.Size

data class KotlinOrderSheet(
val id: String,
val backUrl: String?,
val userNo: Long?,
@field:Size(min = 1, max = 1)
val products: List<OrderSheetProduct>,
val merchantsByMerchantNo: Map.Entry<Long, OrderSheetMerchant>?,
val registeredDateTime: Instant?,
@field:Size(min = 1, max = 1)
val bundleDeliveryFeesByDeliveryGroupKey: Map<String, OrderSheetBundleDeliveryFee>?
) {
data class OrderSheetProduct(
val id: String,
val productName: String?,
val salePrice: BigDecimal?,
val ecMallProductId: String?,
@field:Size(min = 1, max = 1)
val items: List<OrderSheetItem>,
val deliveryPolicy: OrderSheetDeliveryPolicy?,
val merchantNo: Long,
val merchantCategoryItemTypeName: String?,
val wholeCategoryId: String?,
val naverBenefit: Boolean,
val deliveryFee: OrderSheetDeliveryFee?,
val rewardPointPolicy: OrderSheetRewardPointPolicy?
)

data class OrderSheetItem(
val id: String,
val itemNo: String?,
val price: BigDecimal?,
val quantity: Long?,
val orderAmount: BigDecimal?,
@field:Size(min = 1, max = 1)
val elements: List<OrderSheetElement>
)

data class OrderSheetElement(
val id: String,
val elementType: ElementType,
@field:Size(min = 1, max = 1)
val names: List<String>,
@field:Size(min = 1, max = 1)
val valueIds: List<String>,
@field:Size(min = 1, max = 1)
val texts: List<String>
)

data class OrderSheetMerchant(
val talkInterlockAccountId: String?,
val logeyeRequestId: String?,
val logeyeInflowPathName: String?,
val logeyePayAccumulation: Boolean?
)

data class OrderSheetDeliveryPolicy(
val deliveryMethodType: DeliveryMethodType,
val deliveryFeeClassType: DeliveryFeeClassType,
val deliveryFeePayType: DeliveryFeePayType,
val baseFee: BigDecimal?,
val bundlePolicy: OrderSheetDeliveryBundlePolicy?,
val freeConditionalAmount: BigDecimal?
)

data class OrderSheetDeliveryBundlePolicy(
val bundleGroupId: String?
)

data class OrderSheetDeliveryFee(
val deliveryFee: BigDecimal?,
val deliveryGroupKey: String?
)

data class OrderSheetBundleDeliveryFee(
val deliveryFee: BigDecimal?,
val type: BundleType
)

data class OrderSheetRewardPointPolicy(
val purchasePolicyNo: Long?,
val purchaseAccumulateAmount: BigDecimal?
)

enum class DeliveryMethodType {
DELIVERY, VISIT_RECEIPT, DIRECT_DELIVERY, QUICK_SVC, NOTHING
}

enum class ElementType {
OPTION, CUSTOM
}

enum class DeliveryFeeClassType {
CHARGE, FREE
}

enum class DeliveryFeePayType {
PRE_PAY, AFTER_PAY, FREE
}

enum class BundleType {
MANUALLY, IDENTICAL_PRODUCT
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id("com.navercorp.fixturemonkey.gradle.plugin.java-conventions")
}

dependencies {
api(project(":fixture-monkey"))
}

jmh {
fork = 1
warmupIterations = 3
iterations = 10
resultFormat = "CSV"
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,3 @@ public enum BundleType {
IDENTICAL_PRODUCT
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOL is missing now.

Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,3 @@ public enum BundleType {
IDENTICAL_PRODUCT
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOL is missing now.

1 change: 1 addition & 0 deletions fixture-monkey-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect:${Versions.KOTLIN}")

testImplementation(project(":fixture-monkey-jackson"))
testImplementation(project(":fixture-monkey-javax-validation"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this dependency necessary?

Copy link
Contributor Author

@jinia91 jinia91 Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the ExpressionGeneratorJavaTestSpecs, javax validation was previously being used.

Even on the main branch, compile was not successful in my local environment, the exact reason is unclear.

After changing modules, ci compile fails in the absence of the dependency, so it necessary in the current situation.

testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin")
testImplementation("org.junit.jupiter:junit-jupiter-engine:${Versions.JUNIT_JUPITER}")
testImplementation("org.junit.platform:junit-platform-engine:${Versions.JUNIT_ENGINE}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

package com.navercorp.fixturemonkey.kotlin;
package com.navercorp.fixturemonkey.kotlin.spec;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change has nothing to do with this PR.


import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

package com.navercorp.fixturemonkey.kotlin

import com.navercorp.fixturemonkey.kotlin.ExpressionGeneratorJavaTestSpecs.DogJava
import com.navercorp.fixturemonkey.kotlin.ExpressionGeneratorJavaTestSpecs.PersonJava
import com.navercorp.fixturemonkey.kotlin.spec.ExpressionGeneratorJavaTestSpecs.DogJava
import com.navercorp.fixturemonkey.kotlin.spec.ExpressionGeneratorJavaTestSpecs.PersonJava
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change has nothing to do with this PR.

import org.assertj.core.api.BDDAssertions.then
import org.junit.jupiter.api.Test

Expand Down
15 changes: 0 additions & 15 deletions fixture-monkey/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
plugins {
id("me.champeau.jmh") version "0.7.2"
id("com.navercorp.fixturemonkey.gradle.plugin.java-conventions")
id("com.navercorp.fixturemonkey.gradle.plugin.maven-publish-conventions")
}
Expand All @@ -18,18 +17,4 @@ dependencies {
testImplementation("org.assertj:assertj-core:${Versions.ASSERTJ}")
testImplementation("org.projectlombok:lombok:${Versions.LOMBOK}")
testAnnotationProcessor("org.projectlombok:lombok:${Versions.LOMBOK}")

jmhImplementation(project(":fixture-monkey-javax-validation"))
jmhImplementation(project(":fixture-monkey-jackson"))
jmhImplementation("org.openjdk.jmh:jmh-core:${Versions.JMH}")
jmhImplementation("org.openjdk.jmh:jmh-generator-annprocess:${Versions.JMH}")
jmhImplementation("org.projectlombok:lombok:${Versions.LOMBOK}")
jmhAnnotationProcessor("org.projectlombok:lombok:${Versions.LOMBOK}")
}

jmh {
fork = 1
warmupIterations = 3
iterations = 10
resultFormat = "CSV"
}
5 changes: 4 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ include(
"fixture-monkey-tests:java-tests",
"fixture-monkey-tests:java-concurrent-tests",
"fixture-monkey-tests:kotlin-concurrent-tests",
"fixture-monkey-kotest"
"fixture-monkey-kotest",
"fixture-monkey-benchmarks",
"fixture-monkey-benchmarks:fixture-monkey-benchmark",
"fixture-monkey-benchmarks:fixture-monkey-benchmark-kotlin",
)

Loading