<commit_before>#ifndef PROGRESSBAR_H_
#define PROGRESSBAR_H_

#include <iostream>
#include <iomanip>
#include <sys/ioctl.h>
#include <cstdio>

static inline void progressbar(unsigned int progress, unsigned int nitems)
{
    struct winsize w;
    ioctl(0, TIOCGWINSZ, &w);
    unsigned short int bar_width = w.ws_col - 10;

    if ( (progress != nitems) && (progress % (nitems/100+1) != 0) ) return;
 
    float ratio  =  progress/(float)nitems;
    int   c      =  ratio * bar_width;
 
    std::cout << std::setw(3) << (int)(ratio*100) << "% [";
    for (int x=0; x<c; x++) std::cout << "=";
    for (int x=c; x<bar_width; x++) std::cout << " ";
    std::cout << "]\r" << std::flush;
    if (progress >= nitems) std::cout << std::endl;
}

#endif /* PROGRESSBAR_H_ */<commit_msg>Progressbar can now print an optional rate measurement<commit_after>#ifndef PROGRESSBAR_H_
#define PROGRESSBAR_H_

#include <iostream>
#include <iomanip>
#include <sys/ioctl.h>
#include <cstdio>

static inline void progressbar(unsigned int progress, unsigned int nitems,
                               double rate = 0.)
{
    struct winsize w;
    ioctl(0, TIOCGWINSZ, &w);
    unsigned short int bar_width = w.ws_col - 22;

    if ( (progress != nitems) && (progress % (nitems/100+1) != 0) ) return;
 
    float ratio  =  progress/(float)nitems;
    int   c      =  ratio * bar_width;
 
    std::cout << std::setw(3) << (int)(ratio*100) << "% [";
    for (int x=0; x<c; x++) std::cout << "=";
    for (int x=c; x<bar_width; x++) std::cout << " ";
    std::cout << "] ["<< std::fixed << std::setw(6)  << std::setprecision(1) << rate <<"MB/s]\r" << std::flush;
    if (progress >= nitems) std::cout << std::endl;
}

#endif /* PROGRESSBAR_H_ */
{'fraction_non_alphanumeric': 0.18255813953488373, 'fraction_numerical': 0.01686046511627907, 'mean_word_length': 3.3350125944584383, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 13, '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': '6768958', 'n_tokens_mistral': 667, 'n_tokens_neox': 632, 'n_words': 158}