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

Hi Monks,

I come to you yet again with another DBD::SQLite question. If this is off topic, forgive me.

This could also be applied to DBI in general...but I digress.

Anyway, my question is how one would calculate the time it took a query to execute, and count up the number of rows/results returned in that query, like the MySQL command line client does. I've thought of using (times())[0], but I've heard that can be inaccurate.

Ideas monks?

meh.

Replies are listed 'Best First'.
Re: Calculating query time and rows returned in SQLite
by bart (Canon) on Nov 16, 2006 at 11:50 UTC
    I glanced at the SQLite docs, and I couldn't find anything.

    Does it matter where it spent its time, as long as you know how long it took? Because you can get a quite high resolution timestamp out of Time::HiRes, and just calculate the differences.

    #! perl -w use Time::HiRes qw(gettimeofday); use Time::HiRes qw(sleep); # for this demo only my @t = scalar gettimeofday; sleep 3.1415926; push @t, scalar gettimeofday; printf "Total time wasted: %.3f seconds\n", $t[-1]-$t[0];
    The array @ serves two purposes: A) it stores the time measurements in a single variable (you can always use two scalars); and B) you can use it to add intermediate time markers, for more detailed reporting.

      This is more of a feature for the user to see and be like, "Oh, that's cool! This script is fast/slow!", so it doesn't really matter where it spends time, no. I'll try this out, and get back to you. Thanks bart!

      meh.