Skip to content

Conversation

@cushon
Copy link
Contributor

@cushon cushon commented Nov 21, 2025

This implements an API to return the byte length of a String encoded in a given charset. See JDK-8372353 for background.


Benchmark                              (encoding)  (stringLength)   Mode  Cnt          Score           Error  Units
StringLoopJmhBenchmark.getBytes             ASCII              10  thrpt    5  391708261.769 ± 131738312.833  ops/s
StringLoopJmhBenchmark.getBytes             ASCII             100  thrpt    5  177933535.422 ±   3491403.886  ops/s
StringLoopJmhBenchmark.getBytes             ASCII            1000  thrpt    5   39398051.383 ±   4874329.102  ops/s
StringLoopJmhBenchmark.getBytes             ASCII          100000  thrpt    5     450580.669 ±     13486.822  ops/s
StringLoopJmhBenchmark.getBytes            LATIN1              10  thrpt    5   39335958.647 ±   3349851.059  ops/s
StringLoopJmhBenchmark.getBytes            LATIN1             100  thrpt    5   65291332.456 ±   1826481.963  ops/s
StringLoopJmhBenchmark.getBytes            LATIN1            1000  thrpt    5   11357128.475 ±    137592.840  ops/s
StringLoopJmhBenchmark.getBytes            LATIN1          100000  thrpt    5     191677.869 ±      5699.104  ops/s
StringLoopJmhBenchmark.getBytes             UTF16              10  thrpt    5  104280405.379 ±   1105232.322  ops/s
StringLoopJmhBenchmark.getBytes             UTF16             100  thrpt    5   38559775.983 ±   3969525.959  ops/s
StringLoopJmhBenchmark.getBytes             UTF16            1000  thrpt    5    4223120.998 ±     53702.563  ops/s
StringLoopJmhBenchmark.getBytes             UTF16          100000  thrpt    5      56930.445 ±      1575.178  ops/s
StringLoopJmhBenchmark.getBytesLength       ASCII              10  thrpt    5  943085644.673 ±  26102941.766  ops/s
StringLoopJmhBenchmark.getBytesLength       ASCII             100  thrpt    5  391311481.624 ±   6970035.394  ops/s
StringLoopJmhBenchmark.getBytesLength       ASCII            1000  thrpt    5   99419040.393 ±   3951945.216  ops/s
StringLoopJmhBenchmark.getBytesLength       ASCII          100000  thrpt    5    1212863.635 ±      7312.029  ops/s
StringLoopJmhBenchmark.getBytesLength      LATIN1              10  thrpt    5  359884500.225 ±  40809523.322  ops/s
StringLoopJmhBenchmark.getBytesLength      LATIN1             100  thrpt    5  211044735.337 ±   7958529.416  ops/s
StringLoopJmhBenchmark.getBytesLength      LATIN1            1000  thrpt    5   91412629.228 ±   8086023.381  ops/s
StringLoopJmhBenchmark.getBytesLength      LATIN1          100000  thrpt    5    1195691.147 ±     47782.242  ops/s
StringLoopJmhBenchmark.getBytesLength       UTF16              10  thrpt    5  333554560.613 ±   3708669.415  ops/s
StringLoopJmhBenchmark.getBytesLength       UTF16             100  thrpt    5   81021924.141 ±  12571553.763  ops/s
StringLoopJmhBenchmark.getBytesLength       UTF16            1000  thrpt    5   10046196.775 ±   1595086.940  ops/s
StringLoopJmhBenchmark.getBytesLength       UTF16          100000  thrpt    5      99587.224 ±     33212.377  ops/s
StringLoopJmhBenchmark.utf8LenByLoop        ASCII              10  thrpt    5  408274674.923 ±  35589889.027  ops/s
StringLoopJmhBenchmark.utf8LenByLoop        ASCII             100  thrpt    5   79203663.276 ±    350888.625  ops/s
StringLoopJmhBenchmark.utf8LenByLoop        ASCII            1000  thrpt    5    8369222.519 ±    552376.540  ops/s
StringLoopJmhBenchmark.utf8LenByLoop        ASCII          100000  thrpt    5      86842.588 ±     16740.263  ops/s
StringLoopJmhBenchmark.utf8LenByLoop       LATIN1              10  thrpt    5  364012818.025 ±  47011914.698  ops/s
StringLoopJmhBenchmark.utf8LenByLoop       LATIN1             100  thrpt    5   82681217.184 ±   9930544.695  ops/s
StringLoopJmhBenchmark.utf8LenByLoop       LATIN1            1000  thrpt    5   10040934.803 ±   1934154.553  ops/s
StringLoopJmhBenchmark.utf8LenByLoop       LATIN1          100000  thrpt    5      88037.251 ±      3218.885  ops/s
StringLoopJmhBenchmark.utf8LenByLoop        UTF16              10  thrpt    5  304994614.456 ±  39946589.721  ops/s
StringLoopJmhBenchmark.utf8LenByLoop        UTF16             100  thrpt    5   87963328.389 ±   7517439.796  ops/s
StringLoopJmhBenchmark.utf8LenByLoop        UTF16            1000  thrpt    5   10894858.166 ±   2268465.202  ops/s
StringLoopJmhBenchmark.utf8LenByLoop        UTF16          100000  thrpt    5      28255.579 ±      3497.730  ops/s```

<!-- Anything below this marker will be automatically updated, please do not edit manually! -->
---------
### Progress
- [ ] Change must be properly reviewed (1 review required, with at least 1 [Reviewer](https://openjdk.org/bylaws#reviewer))
- [x] Change must not contain extraneous whitespace
- [x] Commit message must refer to an issue

### Issue
 * [JDK-8372353](https://bugs.openjdk.org/browse/JDK-8372353): API to compute the byte length of a String encoded in a given Charset (**Enhancement** - P4)


### Reviewing
<details><summary>Using <code>git</code></summary>

Checkout this PR locally: \
`$ git fetch https://git.openjdk.org/jdk.git pull/28454/head:pull/28454` \
`$ git checkout pull/28454`

Update a local copy of the PR: \
`$ git checkout pull/28454` \
`$ git pull https://git.openjdk.org/jdk.git pull/28454/head`

</details>
<details><summary>Using Skara CLI tools</summary>

Checkout this PR locally: \
`$ git pr checkout 28454`

View PR using the GUI difftool: \
`$ git pr show -t 28454`

</details>
<details><summary>Using diff file</summary>

Download this PR as a diff file: \
<a href="https://git.openjdk.org/jdk/pull/28454.diff">https://git.openjdk.org/jdk/pull/28454.diff</a>

</details>

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 21, 2025

👋 Welcome back cushon! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Nov 21, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Nov 21, 2025

@cushon The following labels will be automatically applied to this pull request:

  • core-libs
  • i18n

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant