xterm_bench.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import 'package:flutter/material.dart';
  2. import 'package:xterm/src/terminal.dart';
  3. class Test extends StatelessWidget {
  4. const Test({Key? key}) : super(key: key);
  5. @override
  6. Widget build(BuildContext context) {
  7. return TextSelectionToolbar(
  8. anchorAbove: Offset(50, 50),
  9. anchorBelow: Offset(50, 50),
  10. children: [
  11. TextSelectionToolbarTextButton(
  12. child: Text('Copy'),
  13. onPressed: () {},
  14. padding: TextSelectionToolbarTextButton.getPadding(0, 1),
  15. ),
  16. TextSelectionToolbarTextButton(
  17. child: Text('Paste'),
  18. onPressed: () {},
  19. padding: TextSelectionToolbarTextButton.getPadding(1, 1),
  20. ),
  21. ],
  22. );
  23. }
  24. }
  25. void main(List<String> args) async {
  26. final lines = 1000;
  27. final terminal = Terminal(maxLines: lines);
  28. bench('write $lines lines', () {
  29. for (var i = 0; i < lines; i++) {
  30. terminal.write('https://github.com/TerminalStudio/dartssh2\r\n');
  31. }
  32. });
  33. final regexp = RegExp(
  34. r'[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)',
  35. );
  36. bench('search $lines line', () {
  37. var count = 0;
  38. for (var line in terminal.lines.toList()) {
  39. final matches = regexp.allMatches(line.toString());
  40. count += matches.length;
  41. }
  42. print('count: $count');
  43. });
  44. }
  45. void bench(String description, void Function() f) {
  46. final sw = Stopwatch()..start();
  47. f();
  48. print('$description took ${sw.elapsedMilliseconds}ms');
  49. }