<commit_before>/**
** Copyright (C) 2010 <NAME>
*/

#include <gtest/gtest.h>
#include <vector>
#include <iostream>
#include <cmath>
#include <qi/transport/src/zmq/zmq_publisher.hpp>
#include <qi/transport/src/zmq/zmq_subscriber.hpp>
#include <qi/perf/sleep.hpp>
#include <boost/timer.hpp>

struct SubscribePerfHandler : qi::transport::TransportSubscribeHandler {
  int fCount;
  int fExpectedMessages;
  boost::timer timer;

  // conforms to ISubscriberHandler
  void subscribeHandler(qi::transport::Buffer& msg) {
    if (fCount == 0) {
      timer.restart();
    }
    fCount++;
    if (fCount != fExpectedMessages) {
      return;
    }
    // print results
    double elapsed = timer.elapsed();
    double msgPerSecond = 1.0 /(elapsed / fExpectedMessages);
    std::cout << "SUB: msg:" << fCount << " msg/s: " <<
      std::setprecision(12) << msgPerSecond << std::endl;
  }

  int getCount() {
    return fCount;
  }

  SubscribePerfHandler() : fCount(0) {}

  SubscribePerfHandler(int expectedMessages) :
    fCount(0),
    fExpectedMessages(expectedMessages) {}
};

TEST(TransportZMQPublisher , HundredThousandPerSecond)
{
  int numMillions = 1;
  int numMessages = numMillions * 100000;
  zmq::context_t ctx1(1);
  zmq::context_t ctx2(1);


  SubscribePerfHandler handler(numMessages);
  //qi::transport::ZMQPublisher publisher1("tcp://127.0.0.1:5556");
  qi::transport::detail::ZMQPublisher publisher(ctx1);
  publisher.bind("tcp://127.0.0.1:5555");
  qi::transport::detail::ZMQSubscriber subscriber(ctx2);
  subscriber.connect("tcp://127.0.0.1:5555");

  subscriber.setSubscribeHandler(&handler);
  subscriber.subscribe();
  std::string msg = "Hello";
  sleep(1);
  for (int i=0; i < numMessages; i++) {
    publisher.publish(msg);
  }

  sleep(10);
  int result = handler.getCount();<commit_msg>Hundred thousand<commit_after>/**
** Copyright (C) 2010 Aldebaran Robotics
*/

#include <gtest/gtest.h>
#include <vector>
#include <iostream>
#include <cmath>
#include <qi/transport/src/zmq/zmq_publisher.hpp>
#include <qi/transport/src/zmq/zmq_subscriber.hpp>
#include <qi/perf/sleep.hpp>
#include <boost/timer.hpp>

struct SubscribePerfHandler : qi::transport::TransportSubscribeHandler {
  int fCount;
  int fExpectedMessages;
  boost::timer timer;

  // conforms to ISubscriberHandler
  void subscribeHandler(qi::transport::Buffer& msg) {
    if (fCount == 0) {
      timer.restart();
    }
    fCount++;
    if (fCount != fExpectedMessages) {
      return;
    }
    // print results
    double elapsed = timer.elapsed();
    double msgPerSecond = 1.0 /(elapsed / fExpectedMessages);
    std::cout << "SUB: msg:" << fCount << " msg/s: " <<
      std::setprecision(12) << msgPerSecond << std::endl;
  }

  int getCount() {
    return fCount;
  }

  SubscribePerfHandler() : fCount(0) {}

  SubscribePerfHandler(int expectedMessages) :
    fCount(0),
    fExpectedMessages(expectedMessages) {}
};

TEST(TransportZMQPublisher , HundredThousand)
{
  int numMillions = 1;
  int numMessages = numMillions * 100000;
  zmq::context_t ctx1(1);
  zmq::context_t ctx2(1);


  SubscribePerfHandler handler(numMessages);
  //qi::transport::ZMQPublisher publisher1("tcp://127.0.0.1:5556");
  qi::transport::detail::ZMQPublisher publisher(ctx1);
  publisher.bind("tcp://127.0.0.1:5555");
  qi::transport::detail::ZMQSubscriber subscriber(ctx2);
  subscriber.connect("tcp://127.0.0.1:5555");

  subscriber.setSubscribeHandler(&handler);
  subscriber.subscribe();
  std::string msg = "Hello";
  sleep(1);
  for (int i=0; i < numMessages; i++) {
    publisher.publish(msg);
  }

  sleep(10);
  int result = handler.getCount();
{'fraction_non_alphanumeric': 0.15865118850193477, 'fraction_numerical': 0.0326147042564953, 'mean_word_length': 4.252539912917271, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '7316946', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1231, 'n_words': 227}