Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open FH is faster than IO::File #264

Open
azumakuniyuki opened this issue Mar 13, 2018 · 0 comments
Open

open FH is faster than IO::File #264

azumakuniyuki opened this issue Mar 13, 2018 · 0 comments
Labels
improvement speed-up Performance Tuning

Comments

@azumakuniyuki
Copy link
Member

#!/usr/bin/env perl
use strict;
use warnings;
use IO::File;
use Benchmark ':all';
use Test::More 'no_plan';

sub iofile {
    my $p = IO::File->new(__FILE__);
    my $e = [];

    push @$e, $_ while <$p>;
    $p->close;
    return $e;
}

sub handle {
    my $e = [];
    open FH, __FILE__;
    push @$e, $_ while <FH>;
    close FH;
    return $e;
}

ok scalar @{ iofile() };
ok scalar @{ handle() };

cmpthese(50000, { 
    'IO::File' => sub { &iofile },
    'open FH,' => sub { &handle },
});
            Rate IO::File open FH,
IO::File 19763/s       --     -26%
open FH, 26596/s      35%       --
1..2
@azumakuniyuki azumakuniyuki added the speed-up Performance Tuning label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement speed-up Performance Tuning
Projects
None yet
Development

No branches or pull requests

1 participant