<commit_before>import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:redis_client/redis_client.dart';
import 'package:redis_client/redis_protocol_transformer.dart';
import 'dart:async';

class PublishBenchmark extends BenchmarkBase {

  PublishBenchmark() : super('PublishBenchmark');

  void run() {
    final datum = '''
{
    "id": 1,
    "name": "A green door",
    "price": 12.50,
    "tags": ["home", "green"]
}''';

    final count = 100;
    List<Future> futures = [];

    final f = RedisClient
      .connect('localhost:6379')
      .then((RedisClient redisClient) {
        for(int i=0; i<10000; i++) {
          redisClient
          .publish('CHAN', '$i=>$datum')
          .then((_) => null);
        }
        redisClient.close();
      });

    Future
      .wait([f])
      .then((_) => null);

  }
}

main() {
  new PublishBenchmark().run();
}<commit_msg>cleaned up the publish example and added timing to it. Seems this is not the best case for benchmarking as it requires long running work to demonstrate the issue which is a different use case than benchmark handles.<commit_after>import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:redis_client/redis_client.dart';
import 'package:redis_client/redis_protocol_transformer.dart';
import 'dart:async';

class PublishBenchmark extends BenchmarkBase {

  PublishBenchmark() : super('PublishBenchmark');

  void run() {
    final datum = '''
{
    "id": 1,
    "name": "A green door",
    "price": 12.50,
    "tags": ["home", "green"]
}''';

    final count = 5000;
    int matched = count;
    final watch = new Stopwatch()..start();

    bool allAccountedFor() => matched == 0;

    final f = RedisClient
      .connect('localhost:6379')
      .then((RedisClient redisClient) {
        List<Future> futures = [];

        for(int i=0; i<count; i++) {
          futures.add(redisClient
              .publish('CHAN', '$i=>$datum')
              .then((_) => matched--));
        }

        Future
          .wait(futures)
          .then((_) => print('''
Time: ${watch.elapsed}
Total published: $count
All Accounted For: ${allAccountedFor()}
'''));

        redisClient.close();
      });
  }
}

main() {
  new PublishBenchmark().run();
}
{'fraction_non_alphanumeric': 0.15606936416184972, 'fraction_numerical': 0.014673188083592708, 'mean_word_length': 2.982300884955752, 'pattern_counts': {'":': 8, '<': 7, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2093396', 'n_tokens_mistral': 765, 'n_tokens_neox': 728, 'n_words': 171}