TROGDOR
A few minor notes:
- As moritz indicated, you haven't proven that the I/O is the problem. You're doing some operations other than reading, any of which may be the problem. Be sure to profile before assigning blame.
- BrowserUk and moritz have also shown you a couple tips to improve the reading speed.
- Perl isn't a "speed is king" language, so having something 1/5 as fast as C isn't altogether unusual. Normally I/O dominates many operations, so perl code is often quite close to C code in wall-clock performance.
- Keep in mind that while perl is slower than C/C++ at some things, it makes other tasks quite simple to do. So often it makes more sense to compare an entire program, rather than one phase of it (I/O).
Just as a reference, I do (in my day job) quite a lot of file processing in both C/C++ and perl. I often find that the perl stuff runs slower, but not enough so that I want to write all my processing programs in C/C++. I find it so much simpler to do regex and complex data munging in perl, that when I have to whack a file using a good bit of intelligence, I tend to use perl first. If I need to whack a large file with just a little simple code and speed is of the essence, I tend to use C/C++. Only rarely do I find that I have to optimize a perl program or rewrite the program to use C/C++.
As usual, YMMV.
...roboticus
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|