-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* kotlinx benchmark added * performance improved * performance doc updated * warmup added * minor tweak * bump kotlinx-io version
- Loading branch information
Showing
24 changed files
with
264 additions
and
54 deletions.
There are no files selected for viewing
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
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
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,23 @@ | ||
plugins { | ||
alias(libs.plugins.kotlinx.benchmark) | ||
alias(libs.plugins.allopen) | ||
} | ||
|
||
allOpen { | ||
annotation("org.openjdk.jmh.annotations.State") | ||
} | ||
|
||
|
||
benchmark { | ||
targets { | ||
register("jvm") | ||
} | ||
|
||
configurations { | ||
named("main") { | ||
// exclude("org.jsoup.parser.JsoupBenchmark") | ||
// exclude("com.fleeksoft.ksoup.benchmark.KsoupBenchmark") | ||
} | ||
} | ||
|
||
} |
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,24 @@ | ||
product: | ||
type: lib | ||
platforms: [ jvm, js, android, linuxX64, linuxArm64, tvosArm64, tvosX64, tvosSimulatorArm64, macosX64, macosArm64, iosArm64, iosSimulatorArm64, iosX64, mingwX64 ] | ||
|
||
apply: [ ../common.module-template.yaml ] | ||
|
||
aliases: | ||
- jvmAndAndroid: [ jvm, android ] | ||
|
||
repositories: | ||
- mavenLocal | ||
|
||
dependencies: | ||
- $libs.kotlinx.io | ||
- $libs.kotlinx.benchmark.runtime | ||
# - com.fleeksoft.ksoup:ksoup-lite:0.1.8 | ||
- ../ksoup | ||
|
||
dependencies@jvm: | ||
- $libs.jsoup | ||
|
||
settings: | ||
kotlin: | ||
optIns: [ kotlinx.cinterop.BetaInteropApi, kotlinx.cinterop.UnsafeNumber, kotlinx.cinterop.ExperimentalForeignApi, kotlin.experimental.ExperimentalNativeApi ] |
49 changes: 49 additions & 0 deletions
49
ksoup-benchmark/src@jvm/com/fleeksoft/ksoup/benchmark/KsoupBenchmark.kt
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,49 @@ | ||
package com.fleeksoft.ksoup.benchmark | ||
|
||
import com.fleeksoft.ksoup.Ksoup | ||
import com.fleeksoft.ksoup.nodes.Document | ||
import com.fleeksoft.ksoup.nodes.Element | ||
import com.fleeksoft.ksoup.select.Elements | ||
import com.fleeksoft.ksoup.select.Evaluator | ||
import kotlinx.benchmark.* | ||
import kotlinx.io.buffered | ||
import kotlinx.io.files.Path | ||
import kotlinx.io.files.SystemFileSystem | ||
import kotlinx.io.readString | ||
|
||
|
||
@State(Scope.Benchmark) | ||
@Warmup(iterations = 5) | ||
@Measurement(iterations = 5, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS) | ||
class KsoupBenchmark { | ||
private lateinit var fileData: String | ||
private lateinit var doc1: Document | ||
|
||
@Setup | ||
fun setUp() { | ||
fileData = | ||
SystemFileSystem.source(Path("/Users/sabeeh/IdeaProjects/ksoup-benchmark/ksoup-test/testResources/test.txt")).buffered().readString() | ||
doc1 = parseHtml() | ||
} | ||
|
||
@Benchmark | ||
fun parse() { | ||
val doc = parseHtml() | ||
} | ||
|
||
@Benchmark | ||
fun select() { | ||
val doc = parseHtml() | ||
doc.getElementsByClass("an-info").mapNotNull { anInfo -> | ||
anInfo.parent()?.let { a -> | ||
val attr = a.attr("href") | ||
if (attr.isEmpty()) return@let null | ||
|
||
attr.substringAfter("/Home/Bangumi/", "") | ||
.takeIf { it.isNotBlank() } | ||
} | ||
} | ||
} | ||
|
||
private fun parseHtml() = Ksoup.parse(fileData) | ||
} |
45 changes: 45 additions & 0 deletions
45
ksoup-benchmark/src@jvm/org/jsoup/parser/JsoupBenchmark.kt
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 @@ | ||
package org.jsoup.parser | ||
|
||
import kotlinx.benchmark.* | ||
import kotlinx.io.buffered | ||
import kotlinx.io.files.Path | ||
import kotlinx.io.files.SystemFileSystem | ||
import kotlinx.io.readString | ||
import org.jsoup.Jsoup | ||
import org.jsoup.nodes.Document | ||
|
||
@State(Scope.Benchmark) | ||
@Warmup(iterations = 5) | ||
@Measurement(iterations = 5, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS) | ||
class JsoupBenchmark { | ||
private lateinit var fileData: String | ||
private lateinit var doc1: Document | ||
|
||
@Setup | ||
fun setUp() { | ||
fileData = | ||
SystemFileSystem.source(Path("/Users/sabeeh/IdeaProjects/ksoup-benchmark/ksoup-test/testResources/test.txt")).buffered().readString() | ||
doc1 = parseHtml() | ||
} | ||
|
||
@Benchmark | ||
fun parse() { | ||
val doc = parseHtml() | ||
} | ||
|
||
@Benchmark | ||
fun select() { | ||
val doc = parseHtml() | ||
doc.getElementsByClass("an-info").mapNotNull { anInfo -> | ||
anInfo.parent()?.let { a -> | ||
val attr = a.attr("href") | ||
if (attr.isEmpty()) return@let null | ||
|
||
attr.substringAfter("/Home/Bangumi/", "") | ||
.takeIf { it.isNotBlank() } | ||
} | ||
} | ||
} | ||
|
||
private fun parseHtml() = Jsoup.parse(fileData) | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.