<commit_before>#!/usr/bin/env perl

# Pragmas.
use strict;
use warnings;

# Module.
use Benchmark qw(cmpthese);
use IO::Any;
use IO::Barf;
use File::Slurp qw(write_file);
use File::Temp;

# Temporary files.
my $temp1 = File::Temp->new->filename;
my $temp2 = File::Temp->new->filename;
my $temp3 = File::Temp->new->filename;

# Some data.
my $data = 'x' x 1000;

# Benchmark (10s).
cmpthese(-10, {
        'IO::Any' => sub {
                IO::Any->spew($temp2, $data);
                unlink $temp2;
        },
        'IO::Barf' => sub {
                barf($temp1, $data);
                unlink $temp1;
        },
        'File::Slurp' => sub {
                write_file($temp3, $data);
                unlink $temp3;
        },
});

# Output like this:
#                Rate     IO::Any File::Slurp    IO::Barf
# IO::Any      6382/s          --        -24%        -48%
# File::Slurp  8367/s         31%          --        -32%
# IO::Barf    12268/s         92%         47%          --<commit_msg>Update examples.<commit_after>#!/usr/bin/env perl

# Pragmas.
use strict;
use warnings;

# Module.
use Benchmark qw(cmpthese);
use IO::Any;
use IO::Barf;
use File::Slurp qw(write_file);
use File::Temp;

# Temporary files.
my $temp1 = File::Temp->new->filename;
my $temp2 = File::Temp->new->filename;
my $temp3 = File::Temp->new->filename;

# Some data.
my $data = 'x' x 1000;

# Benchmark (10s).
cmpthese(-10, {
        'File::Slurp' => sub {
                write_file($temp3, $data);
                unlink $temp3;
        },
        'IO::Any' => sub {
                IO::Any->spew($temp2, $data);
                unlink $temp2;
        },
        'IO::Barf' => sub {
                barf($temp1, $data);
                unlink $temp1;
        },
});

# Output like this:
#                Rate     IO::Any File::Slurp    IO::Barf
# IO::Any      6382/s          --        -24%        -48%
# File::Slurp  8367/s         31%          --        -32%
# IO::Barf    12268/s         92%         47%          --
{'fraction_non_alphanumeric': 0.16874066699850673, 'fraction_numerical': 0.041811846689895474, 'mean_word_length': 1.5935483870967742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1149107', 'n_tokens_mistral': 774, 'n_tokens_neox': 715, 'n_words': 157}