Add segmenter comparison benchmarks#8141
Open
Xuanwo wants to merge 3 commits into
Open
Conversation
This was referenced Jun 26, 2026
| const TEXT_JAPANESE: &str = | ||
| "こんにちは世界こんにちは世界こんにちは世界こんにちは世界こんにちは世界こんにちは世界"; | ||
| const TEXT_HAN: &str = "中文分词需要词典中文分词需要词典中文分词需要词典中文分词需要词典"; | ||
| const TEXT_THAI_JAPANESE: &str = "ภาษาไทยこんにちは世界ภาษาไทยこんにちは世界ภาษาไทยこんにちは世界"; |
Member
There was a problem hiding this comment.
complex mixes are good, but also add mixed complex/non-complex text
| }); | ||
|
|
||
| group.bench_function("En CSS", |b| { | ||
| group.bench_function("published_dictionary_css/english", |b| { |
Member
There was a problem hiding this comment.
the new names are nicer, but please don't rename benchmarks, it will break our graphs
| const TEST_STR_TH: &str = | ||
| "ภาษาไทยภาษาไทย ภาษาไทยภาษาไทย ภาษาไทยภาษาไทย ภาษาไทยภาษาไทย ภาษาไทยภาษาไทย ภาษาไทยภาษาไทย"; | ||
| const TEXT_ENGLISH: &str = "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."; | ||
| const TEXT_THAI: &str = |
Member
There was a problem hiding this comment.
you probably want longer texts to really notice allocations. like a whole wikipedia article or something.
you can check text files into tests/testdata and then load them here
| const TEST_STR_EN: &str = "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."; | ||
| const TEST_STR_TH: &str = | ||
| "ภาษาไทยภาษาไทย ภาษาไทยภาษาไทย ภาษาไทยภาษาไทย ภาษาไทยภาษาไทย ภาษาไทยภาษาไทย ภาษาไทยภาษาไทย"; | ||
| const TEXT_ENGLISH: &str = "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."; |
Member
There was a problem hiding this comment.
please try to reduce diffs. there's no reason for renaming this constant or removing the comment
|
|
||
| group.bench_function("published_dictionary/english", |b| { | ||
| b.iter(|| { | ||
| consume_breakpoints( |
Member
There was a problem hiding this comment.
what's the reason for replacing count by consume_breakpoints?
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changelog
No changelog entry is required: this PR only changes benchmark code.
Summary
This PR publishes segmenter comparison benchmarks without changing segmenter behavior or public APIs.
The benchmark matrix covers word and line segmentation across
segment_str,segment_utf8, andsegment_utf16. It includes English, Thai, Japanese, Han, Thai+Japanese, and Thai+Han inputs so follow-up optimization PRs can separately validate dictionary and complex-language traversal changes.By default, the benchmark compiles and runs the published segmenter implementation. With the
unstablefeature enabled, it also registers matchingneobenchmarks. The comparison matrix includesauto,lstm, anddictionaryconstructor variants, plus line-break CSS option cases for English.The benchmarks consume iterators with a checksum instead of collecting breakpoints, so result collection allocation is not part of the measured path.
How to run
Compile the default published-segmenter benchmark:
Compile the published-vs-neo comparison benchmark:
Run the comparison benchmark:
For a quick smoke run while iterating:
Follow-up PRs for segmenter optimizations can use the stable Criterion names under
Segmenter/{line,word}/{segment_str,segment_utf8,segment_utf16}/{published,neo}_{auto,lstm,dictionary}/{case}andSegmenter/line/segment_{latin1,str,utf8,utf16}/{published,neo}_dictionary_css/englishto compare improvements independently.