-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor cleanup and simplification of readString
* Request Long.MAX_VALUE from the source at once (note: no need for a loop as we are unable to build the string of such size anyway) * Get rid of redundant checks in commonReadUtf8 Ticks one of the boxes in #342
- Loading branch information
Showing
3 changed files
with
55 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package kotlinx.io.benchmarks | ||
|
||
import kotlinx.benchmark.Benchmark | ||
import kotlinx.benchmark.Param | ||
import kotlinx.benchmark.Scope | ||
import kotlinx.benchmark.Setup | ||
import kotlinx.benchmark.State | ||
import kotlinx.io.Buffer | ||
import kotlinx.io.Source | ||
import kotlinx.io.readCodePointValue | ||
import kotlinx.io.readString | ||
import kotlinx.io.writeCodePointValue | ||
import kotlinx.io.writeString | ||
import kotlin.random.Random | ||
|
||
|
||
@State(Scope.Benchmark) | ||
open class ReadStringBenchmark() { | ||
|
||
@Param("16", "64", "512") | ||
var size: Int = 0 | ||
|
||
val buffer: Buffer = Buffer() | ||
|
||
@Setup | ||
fun setup() { | ||
val string = buildString { repeat(size) { append(('a'..'z').random()) } } | ||
buffer.writeString(string) | ||
} | ||
|
||
|
||
@Benchmark | ||
fun bufferReadString(): String { | ||
return buffer.copy().readString() | ||
} | ||
|
||
@Benchmark | ||
fun sourceReadString(): String { | ||
val source: Source = buffer.copy() | ||
return source.readString() | ||
} | ||
} |
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