http://qs1969.pair.com?node_id=837624

TROGDOR has asked for the wisdom of the Perl Monks concerning the following question:

Greetings fellow monks,

I am a strong advocate of perl, so I was very disappointed today when I ran some disk benchmarks and found that perl disk IO seems to be very slow.

I'm writing a gds parser. gds is a binary file format that defines a microchip layout. I wrote a very simple perl script for benchmark testing that just opens the file and reads it in using read commands, without actually doing anything with the data. The code is included below.

This script processes 10 megs of data per second. An equivalent C program that does the exact same thing processes 50 megs of data per second. Why is perl's IO so slow, and is there anything I can do to improve it? Is there an IO module with a more efficient implementation?

Thanks,
TROGDOR
open (FILE, "$path") or die "ERROR: Could not open $path.\n"; while (1) { $eof = read (FILE, $header, 4); ($size, $code, $ftype) = unpack ("nCC", $header) ; if ($size == 0) { print "Size is zero. Exiting.\n"; last; } $size = $size - 4; if ($size > 0) { $eof = read (FILE, $data, $size); } } close FILE;