.readline() -SOLVED: PYTHON FASTER THAN PERL !

Mats Kindahl matkin at iar.se
Tue Nov 21 12:17:28 CET 2000


"Harald Schneider" <h_schneider at marketmix.com> writes:

> FANTASTIC !
> 1.52 sec. with your code (PERL was: 3.705)
> 
> You gave me the reason to dig more into Python :) Thanks a lot!

[snip]

In fairness to Perl, you should use a more "Perl-ionic"
("Perl-iodic"?) approach as well---i.e., using regular expressions
instead of splitting the string.

Try the following version of your code.

    #!/usr/bin/perl

    use Time::HiRes;

    $_db = 'test.dat';
    print "Running...\n";

    $secStart = Time::HiRes::time;

    open(DB, "<$_db") or die "Can't open $_db";
    while ($dbline = <DB>) {
	if ($dbline =~ /^TEST/) {
	    print("FOUND: $dbline\n");
	    last;
	}
    }
    print("DONE!\n");
    close(DB);
    printf("Elapsed time: %f sec.\n", (Time::HiRes::time - $secStart));

    exit(0);
 
It was significantly faster on my test input.

Just another Perl/Python hacker,

-- 
Mats Kindahl, IAR Systems, Sweden

Any opinions expressed are my own, not my company's.



More information about the Python-list mailing list