This repository was archived by the owner on Feb 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
move to package:args for cli arg parsing #15
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d6ced85
change dependencies
unsuitable001 55d18d1
migrate bin/setup.dart to use package:args
unsuitable001 d5df30b
use package:args in benchmark/ files
unsuitable001 94ed998
bump version, add: changelog, example readme (pub points) and correct…
unsuitable001 3f5765a
benchmark: duration as milliseconds
unsuitable001 3bb5800
benchmark: milliseconds to seconds
unsuitable001 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ import 'dart:convert'; | |
import 'dart:io'; | ||
import 'dart:math'; | ||
|
||
import 'package:args/args.dart'; | ||
|
||
import 'latency.dart'; | ||
import 'throughput.dart'; | ||
|
||
|
@@ -24,27 +26,46 @@ List<int> throughputParserHelper(String aotThroughputStdout) { | |
} | ||
|
||
void main(List<String> args) async { | ||
var url = 'https://example.com'; | ||
var throughputPrallelLimit = 10; | ||
var duration = const Duration(seconds: 1); | ||
if (args.isNotEmpty) { | ||
url = args[0]; | ||
} | ||
if (args.length > 1) { | ||
throughputPrallelLimit = int.parse(args[1]).toInt(); | ||
final parser = ArgParser(); | ||
parser | ||
..addOption('url', | ||
abbr: 'u', | ||
help: 'The server to ping for running this benchmark.', | ||
defaultsTo: 'https://example.com') | ||
..addOption('limit', | ||
abbr: 'l', | ||
help: 'Limits the maximum number of parallel requests to 2^N where N' | ||
' is provided through this option.', | ||
defaultsTo: '10') | ||
..addOption('time', | ||
abbr: 't', | ||
help: 'Maximum second(s) the benchmark should wait for each request.', | ||
defaultsTo: '1') | ||
..addFlag('help', | ||
abbr: 'h', negatable: false, help: 'Print this usage information.'); | ||
final arguments = parser.parse(args); | ||
if (arguments.wasParsed('help')) { | ||
print(parser.usage); | ||
return; | ||
} | ||
if (args.length > 2) { | ||
duration = Duration(seconds: int.parse(args[2])); | ||
if (arguments.rest.isNotEmpty) { | ||
print(parser.usage); | ||
throw ArgumentError(); | ||
} | ||
final url = arguments['url'] as String; | ||
final throughputPrallelLimit = int.parse(arguments['limit'] as String); | ||
final duration = Duration(seconds: int.parse(arguments['time'] as String)); | ||
|
||
print('Latency Test against: $url'); | ||
print('JIT'); | ||
final jitCronetLatency = await CronetLatencyBenchmark.main(url); | ||
final jitDartIOLatency = await DartIOLatencyBenchmark.main(url); | ||
|
||
print('AOT'); | ||
print('Compiling...'); | ||
Process.runSync('dart', ['compile', 'exe', 'benchmarks/latency.dart']); | ||
final aotLantencyProc = await Process.start('benchmarks/latency.exe', [url]); | ||
Process.runSync('dart', ['compile', 'exe', 'benchmark/latency.dart']); | ||
final aotLantencyProc = | ||
await Process.start('benchmark/latency.exe', ['-u', url]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do the 'exe' files compiled by dart only work on windows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No 😅. It is named as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes. I see it now in the documentation. Dart supports quite a few different compilation formats 😀 |
||
stderr.addStream(aotLantencyProc.stderr); | ||
var latencyStdout = ''; | ||
await for (final chunk in aotLantencyProc.stdout.transform(utf8.decoder)) { | ||
|
@@ -67,9 +88,15 @@ void main(List<String> args) async { | |
|
||
print('AOT'); | ||
print('Compiling...'); | ||
Process.runSync('dart', ['compile', 'exe', 'benchmarks/throughput.dart']); | ||
final aotThroughputProc = await Process.start('benchmarks/throughput.exe', | ||
[url, throughputPrallelLimit.toString(), duration.inSeconds.toString()]); | ||
Process.runSync('dart', ['compile', 'exe', 'benchmark/throughput.dart']); | ||
final aotThroughputProc = await Process.start('benchmark/throughput.exe', [ | ||
'-u', | ||
url, | ||
'-l', | ||
throughputPrallelLimit.toString(), | ||
'-t', | ||
duration.inSeconds.toString() | ||
]); | ||
stderr.addStream(aotThroughputProc.stderr); | ||
var throughputStdout = ''; | ||
await for (final chunk in aotThroughputProc.stdout.transform(utf8.decoder)) { | ||
|
@@ -90,7 +117,7 @@ void main(List<String> args) async { | |
' ${jitDartIOLatency.toStringAsFixed(3)} ms |'); | ||
print('| AOT | ${aotCronetLatency.toStringAsFixed(3)} ms |' | ||
' ${aotDartIOLatency.toStringAsFixed(3)} ms |'); | ||
print('\n\nThroughput Test Results (Duration ${duration.inSeconds}'); | ||
print('\nThroughput Test Results (Duration: ${duration.inSeconds}s)'); | ||
print('| Mode | package:cronet | dart:io |'); | ||
print('| :-----------: |:--------------: | :-----------: |'); | ||
print('| JIT | ${jitCronetThroughput[1]} out of' | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## Examples | ||
|
||
- [Bare Minimum](https://github.com/google/cronet.dart#example) | ||
- [Simple (Dart CLI)](https://github.com/google/cronet.dart/tree/main/example/) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work with half a second?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
Duration
'sseconds
param takesint
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should do milliseconds instead then, or convert a double manually. Because otherwise we can't test shorter durations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go with milliseconds then 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got this result under short duration. Cronet is so much faster.
Latency Test Results
Throughput Test Results (Duration: 500 ms)