xterm_bench.dart 818 B

1234567891011121314151617181920212223242526272829303132
  1. import 'package:xterm/src/terminal.dart';
  2. void main(List<String> args) async {
  3. final lines = 1000;
  4. final terminal = Terminal(maxLines: lines);
  5. bench('write $lines lines', () {
  6. for (var i = 0; i < lines; i++) {
  7. terminal.write('https://github.com/TerminalStudio/dartssh2\r\n');
  8. }
  9. });
  10. final regexp = RegExp(
  11. r'[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)',
  12. );
  13. bench('search $lines line', () {
  14. var count = 0;
  15. for (var line in terminal.lines.toList()) {
  16. final matches = regexp.allMatches(line.toString());
  17. count += matches.length;
  18. }
  19. print('count: $count');
  20. });
  21. }
  22. void bench(String description, void Function() f) {
  23. final sw = Stopwatch()..start();
  24. f();
  25. print('$description took ${sw.elapsedMilliseconds}ms');
  26. }