-
Notifications
You must be signed in to change notification settings - Fork 648
JVM integration with InputStream and OutputStream #1569
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4183b8a
Working draft
sandwwraith 1405635
Extract functions and add correct naming
sandwwraith 036936d
Change from file benchmarks to BAOS/IS benchmarks
sandwwraith bb0dc8f
Performance-friendly JsonLexer (#1635)
qwwdfsad 7dc9272
Removed charset from public api
sandwwraith 9362f5f
Force EOF after reading an object from stream
sandwwraith bd8c491
~review fixes
sandwwraith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
benchmark/src/jmh/kotlin/kotlinx/benchmarks/json/TwitterFeedStreamBenchmark.kt
This file contains hidden or 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,82 @@ | ||
package kotlinx.benchmarks.json | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import kotlinx.benchmarks.model.MacroTwitterFeed | ||
import kotlinx.benchmarks.model.MicroTwitterFeed | ||
import kotlinx.serialization.json.* | ||
import org.openjdk.jmh.annotations.* | ||
import java.io.* | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.util.concurrent.TimeUnit | ||
import kotlin.io.path.deleteIfExists | ||
import kotlin.io.path.outputStream | ||
|
||
@Warmup(iterations = 7, time = 1) | ||
@Measurement(iterations = 7, time = 1) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
@State(Scope.Benchmark) | ||
@Fork(2) | ||
open class TwitterFeedStreamBenchmark { | ||
val resource = TwitterFeedBenchmark::class.java.getResource("/twitter_macro.json")!! | ||
val bytes = resource.readBytes() | ||
private val twitter = Json.decodeFromString(MacroTwitterFeed.serializer(), resource.readText()) | ||
|
||
private val jsonIgnoreUnknwn = Json { ignoreUnknownKeys = true } | ||
private val objectMapper: ObjectMapper = | ||
jacksonObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
|
||
|
||
private val inputStream: InputStream | ||
get() = ByteArrayInputStream(bytes) | ||
private val outputStream: OutputStream | ||
get() = ByteArrayOutputStream() | ||
|
||
@Benchmark | ||
fun encodeTwitterWriteText(): OutputStream { | ||
return outputStream.use { | ||
it.bufferedWriter().write(Json.encodeToString(MacroTwitterFeed.serializer(), twitter)) | ||
it | ||
} | ||
} | ||
|
||
@Benchmark | ||
fun encodeTwitterWriteStream(): OutputStream { | ||
return outputStream.use { | ||
Json.encodeToStream(MacroTwitterFeed.serializer(), twitter, it) | ||
it | ||
} | ||
} | ||
|
||
@Benchmark | ||
fun encodeTwitterJacksonStream(): OutputStream { | ||
return outputStream.use { | ||
objectMapper.writeValue(it, twitter) | ||
it | ||
} | ||
} | ||
|
||
@Benchmark | ||
fun decodeMicroTwitterReadText(): MicroTwitterFeed { | ||
return inputStream.use { | ||
jsonIgnoreUnknwn.decodeFromString(MicroTwitterFeed.serializer(), it.bufferedReader().readText()) | ||
} | ||
} | ||
|
||
@Benchmark | ||
fun decodeMicroTwitterStream(): MicroTwitterFeed { | ||
return inputStream.use { | ||
jsonIgnoreUnknwn.decodeFromStream(MicroTwitterFeed.serializer(), it.buffered()) | ||
} | ||
} | ||
|
||
@Benchmark | ||
fun decodeMicroTwitterJacksonStream(): MicroTwitterFeed { | ||
return inputStream.use { | ||
objectMapper.readValue(it, MicroTwitterFeed::class.java) | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.