-
Notifications
You must be signed in to change notification settings - Fork 87
Optimize LineScanner newline detection and fix backwards position bug #2342
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
+204
−66
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bae4cc8
Optimize LineScanner newline detection and fix backwards position bug
kevmoo 292dd7e
Address code review comments
kevmoo b0b27af
put back nice util usage
kevmoo 27d3ceb
Address PR 2342 comments
kevmoo 24d230d
chore: remove firehose output files
kevmoo c7cf96f
oops
kevmoo 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
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,104 @@ | ||
| // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'package:benchmark_harness/benchmark_harness.dart'; | ||
| import 'package:string_scanner/string_scanner.dart'; | ||
|
|
||
| final _string = 'This is a test string with some typical content.\n' * 50000; | ||
| final _word = RegExp(r'\w+'); | ||
| final _space = RegExp(r'\s+'); | ||
|
|
||
| class StringScannerReadCharBenchmark extends BenchmarkBase { | ||
| StringScannerReadCharBenchmark() : super('StringScanner readChar'); | ||
|
|
||
| @override | ||
| void run() { | ||
| final scanner = StringScanner(_string); | ||
| while (!scanner.isDone) { | ||
| scanner.readChar(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class LineScannerReadCharBenchmark extends BenchmarkBase { | ||
| LineScannerReadCharBenchmark() : super('LineScanner readChar'); | ||
|
|
||
| @override | ||
| void run() { | ||
| final scanner = LineScanner(_string); | ||
| while (!scanner.isDone) { | ||
| scanner.readChar(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class SpanScannerReadCharBenchmark extends BenchmarkBase { | ||
| SpanScannerReadCharBenchmark() : super('SpanScanner readChar'); | ||
|
|
||
| @override | ||
| void run() { | ||
| final scanner = SpanScanner(_string); | ||
| while (!scanner.isDone) { | ||
| scanner.readChar(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class StringScannerScanBenchmark extends BenchmarkBase { | ||
| StringScannerScanBenchmark() : super('StringScanner scan'); | ||
|
|
||
| @override | ||
| void run() { | ||
| final scanner = StringScanner(_string); | ||
| while (!scanner.isDone) { | ||
| if (!scanner.scan(_word) && | ||
| !scanner.scanChar(10) && | ||
| !scanner.scan(_space)) { | ||
| scanner.readChar(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class LineScannerScanBenchmark extends BenchmarkBase { | ||
| LineScannerScanBenchmark() : super('LineScanner scan'); | ||
|
|
||
| @override | ||
| void run() { | ||
| final scanner = LineScanner(_string); | ||
| while (!scanner.isDone) { | ||
| if (!scanner.scan(_word) && | ||
| !scanner.scanChar(10) && | ||
| !scanner.scan(_space)) { | ||
| scanner.readChar(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class SpanScannerScanBenchmark extends BenchmarkBase { | ||
| SpanScannerScanBenchmark() : super('SpanScanner scan'); | ||
|
|
||
| @override | ||
| void run() { | ||
| final scanner = SpanScanner(_string); | ||
| while (!scanner.isDone) { | ||
| if (!scanner.scan(_word) && | ||
| !scanner.scanChar(10) && | ||
| !scanner.scan(_space)) { | ||
| scanner.readChar(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void main() { | ||
| print('String length: ${_string.length}'); | ||
| StringScannerReadCharBenchmark().report(); | ||
| LineScannerReadCharBenchmark().report(); | ||
| SpanScannerReadCharBenchmark().report(); | ||
| StringScannerScanBenchmark().report(); | ||
| LineScannerScanBenchmark().report(); | ||
| SpanScannerScanBenchmark().report(); | ||
| } |
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.