<commit_before>
#pragma once

#include <iostream>
#include <thread>
#include <chrono>
#include <boost/asio.hpp>

#include "common.h"

#define MAX_PACKET_SIZE	65536

using namespace boost::asio;
using namespace std::chrono;

class test_latency_client
{
private:
    enum { PACKET_SIZE = MAX_PACKET_SIZE };
    
    boost::asio::io_service & io_service_;
    ip::tcp::socket socket_;
    std::uint32_t packet_size_;

    uint64_t last_query_count_;
    uint64_t total_query_count_;
    double last_total_latency_;   
    double total_latency_;

    duration<double> elapsed_time_;
    time_point<high_resolution_clock> send_time_;
    time_point<high_resolution_clock> recieve_time_;
    time_point<high_resolution_clock> last_time_;

    char data_[PACKET_SIZE];

public:
    test_latency_client(boost::asio::io_service & io_service,
        ip::tcp::resolver::iterator endpoint_iterator, std::uint32_t packet_size)
        : io_service_(io_service),
          socket_(io_service), packet_size_(packet_size),
          last_query_count_(0), total_query_count_(0), last_total_latency_(0.0), total_latency_(0.0)
    {
        ::memset(data_, 'h', sizeof(data_));
        last_time_ = high_resolution_clock::now();
        do_connect(endpoint_iterator);
    }

    ~test_latency_client()
    {
        time_point<high_resolution_clock> startime = high_resolution_clock::now();

        time_point<high_resolution_clock> endtime = high_resolution_clock::now();
        duration<double> elapsed_time = duration_cast< duration<double> >(endtime - startime);
    }

private:
    void display_counters()
    {
        elapsed_time_ = duration_cast< duration<double> >(recieve_time_ - send_time_);
        last_query_count_++;
        total_query_count_++;
        last_total_latency_ += elapsed_time_.count();
        total_latency_ += elapsed_time_.count();
        time_point<high_resolution_clock> now_time = high_resolution_clock::now();
        duration<double> interval_time = duration_cast< duration<double> >(now_time - last_time_);
        double avg_latency, avg_total_latency;
        if (interval_time.count() > 1.0) {
            std::cout << "packet_size =" << packet_size_ << " B, latency total = " << last_total_latency_ << " ms" <<  std::endl;<commit_msg>小改动.<commit_after>
#pragma once

#include <iostream>
#include <thread>
#include <chrono>
#include <boost/asio.hpp>

#include "common.h"

#define MAX_PACKET_SIZE	65536

using namespace boost::asio;
using namespace std::chrono;

class test_latency_client
{
private:
    enum { PACKET_SIZE = MAX_PACKET_SIZE };
    
    boost::asio::io_service & io_service_;
    ip::tcp::socket socket_;
    std::uint32_t packet_size_;

    uint64_t last_query_count_;
    uint64_t total_query_count_;
    double last_total_latency_;   
    double total_latency_;

    duration<double> elapsed_time_;
    time_point<high_resolution_clock> send_time_;
    time_point<high_resolution_clock> recieve_time_;
    time_point<high_resolution_clock> last_time_;

    char data_[PACKET_SIZE];

public:
    test_latency_client(boost::asio::io_service & io_service,
        ip::tcp::resolver::iterator endpoint_iterator, std::uint32_t packet_size)
        : io_service_(io_service),
          socket_(io_service), packet_size_(packet_size),
          last_query_count_(0), total_query_count_(0), last_total_latency_(0.0), total_latency_(0.0)
    {
        ::memset(data_, 'h', sizeof(data_));
        last_time_ = high_resolution_clock::now();
        do_connect(endpoint_iterator);
    }

    ~test_latency_client()
    {
        time_point<high_resolution_clock> startime = high_resolution_clock::now();

        time_point<high_resolution_clock> endtime = high_resolution_clock::now();
        duration<double> elapsed_time = duration_cast< duration<double> >(endtime - startime);
    }

private:
    void display_counters()
    {
        elapsed_time_ = duration_cast< duration<double> >(recieve_time_ - send_time_);
        last_query_count_++;
        total_query_count_++;
        last_total_latency_ += elapsed_time_.count();
        total_latency_ += elapsed_time_.count();
        time_point<high_resolution_clock> now_time = high_resolution_clock::now();
        duration<double> interval_time = duration_cast< duration<double> >(now_time - last_time_);
        double avg_latency, avg_total_latency;
        if (interval_time.count() > 1.0) {
            std::cout << "packet_size = " << packet_size_ << " B,                 latency total = "
                      << last_total_latency_ << " ms" <<  std::endl;
{'fraction_non_alphanumeric': 0.10952589991220368, 'fraction_numerical': 0.009218612818261633, 'mean_word_length': 3.905274488697524, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 43, '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': '5389258', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1463, 'n_words': 245}