Ancient

 view release on metacpan or  search on metacpan

bench/file.pl  view on Meta::CPAN

# ============================================

print "\n--- ATIME ---\n";
cmpthese(-2, {
    'file::atime' => sub {
        my $a = file::atime($small_file);
    },
    'Perl stat atime' => sub {
        my $a = (stat($small_file))[8];
    },
});

print "\n--- MODE ---\n";
cmpthese(-2, {
    'file::mode' => sub {
        my $m = file::mode($small_file);
    },
    'Perl stat mode' => sub {
        my $m = (stat($small_file))[2] & 07777;
    },
});

print "\n--- IS_LINK ---\n";
cmpthese(-2, {
    'file::is_link' => sub {
        my $l = file::is_link($small_file);
    },
    'Perl -l' => sub {
        my $l = -l $small_file;
    },
});

print "\n=== Summary ===\n";
print "file:: uses direct syscalls bypassing PerlIO overhead\n";
print "\n";
print "Performance highlights:\n";
print "  - Large file slurp:  ~2.7x faster (pre-allocated buffer)\n";
print "  - Large file spew:   ~3x faster (direct write)\n";
print "  - Lines array:       ~2x faster (optimized split)\n";
print "  - Copy large file:   ~1.5-2x faster (direct syscalls)\n";
print "  - Readdir:           ~1.3x faster (no OO overhead)\n";
print "  - Basename/Dirname:  ~3-5x faster (no module load, pure C)\n";
print "  - Head:              ~2x faster (early termination)\n";
print "\n";
print "Custom ops (file_* functions) vs method calls:\n";
print "  - file_slurp:    2-3% faster than file::slurp\n";
print "  - file_spew:     2-6% faster than file::spew\n";
print "  - file_unlink:   2-5% faster than file::unlink\n";
print "  - file_mkdir:    2-5% faster than file::mkdir\n";
print "  - file_basename: 2-5% faster than file::basename\n";
print "\n";
print "Usage:\n";
print "  use file qw(import);  # Import file_slurp, file_spew, etc.\n";
print "  my \$c = file_slurp(\$path);  # Uses custom op\n";
print "\n";
print "All file:: functions:\n";
print "  I/O:      slurp, slurp_raw, spew, append, atomic_spew\n";
print "  Lines:    lines, lines_iter, each_line, head, tail\n";
print "  Stat:     size, mtime, atime, ctime, mode, exists\n";
print "  Type:     is_file, is_dir, is_link, is_readable, is_writable, is_executable\n";
print "  Ops:      unlink, copy, move, touch, chmod, mkdir, rmdir, readdir\n";
print "  Path:     basename, dirname, extname, join\n";
print "  Memory:   mmap_open (returns object with data, sync, close methods)\n";



( run in 0.607 second using v1.01-cache-2.11-cpan-39bf76dae61 )