Scott K Purcell wrote:

> I was wondering if there is a speed difference between using IO::File
> versus a standard opening of a file with a filehandle.

There seems to be.

> Then I thought that there is a benchmark module (which I have never used)
> and was wondering if it is possible to use the benchmark module and
> benchmark IO::File opening a file, versus the standard open (FH, bla bla).

Benchmark: running Opening and closing using regular filehandles,
Writing to file and re-reading, each for at least 5 CPU seconds...
Opening and closing using regular filehandles:  6 wallclock secs ( 2.45
usr +  2.61 sys =  5.06 CPU) @ 33728.26/s (n=170665)
Writing to file and re-reading:  6 wallclock secs ( 5.96 usr +  0.42 sys
=  6.38 CPU) @  6.74/s (n=43)
Benchmark: running Opening and closing using IO::File, Writing to file
and re-reading using IO::File, each for at least 5 CPU seconds...
Opening and closing using IO::File:  5 wallclock secs ( 4.04 usr +  0.97
sys =  5.01 CPU) @ 8719.36/s (n=43684)
Writing to file and re-reading using IO::File:  9 wallclock secs ( 9.17
usr +  0.28 sys =  9.45 CPU) @  3.39/s (n=32)

-----------------

use Benchmark;
use IO::File;
my $minimumTime = -5;
my $testString = ('a' x 99) . "\n";
my $fileName = 'test.file';

unlink($fileName);

timethese($minimumTime, {
        'Opening and closing using regular filehandles' => sub {
                open FILE, "> $fileName";
                close FILE;
        },
        'Writing to file and re-reading' => sub {
                open FILE, "+< $fileName";
                for (my $i = 0; $i < 10000; $i++)
                {
                        print FILE $testString;
                }
                seek(FILE, 0, 0);
                1 while (<FILE>);
        }
});

unlink($fileName);

my $file = IO::File->new();

timethese($minimumTime, {
        'Opening and closing using IO::File' => sub {
                $file->open($fileName, 'w');
                $file->close();
        },
        'Writing to file and re-reading using IO::File' => sub {
                $file->open($fileName, 'r+');
                for (my $i = 0; $i < 10000; $i++)
                {
                        $file->print($testString);
                }
                $file->seek(0, 0);
                1 while ($file->getline());
        }
});

-- 
Ned Konz
currently: Stanwood, WA
email:     [EMAIL PROTECTED]
homepage:  http://bike-nomad.com, Perl homepage:
http://bike-nomad.com/perl

---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to