To show that interpreted languages can be plenty fast when used well, I’m posting this example.
Take the On-line Encyclopedia of Integer Sequences database, which is a collection of integer sequences. That means lists of numbers. You can get a file from http://oeis.org/stripped.gz, which contains the first few numbers of each sequence. The file as at the time of writing file extracts to about 38MB.
I need to do lookups in this file for a program I’m writing, and that program is in PHP. I want to be able to look up sequences based on their A-number, like this:
|
|
If we’re economical about it, then even this large-ish file can be parsed in fractions of a second. Here’s how we do it:
|
|
Note that we don’t use explode()
until after we have found the line we need, and also note that file_get_contents()
is not used at all. (As strings get larger they will bog you down in any language).