android - Time required by some statements to execute not constant -
inside sqlite adapter
class, android application, have following method. key key_was
can either 0 or 1. method searches given name
, given date
in database (for given date there can 1 unique entry particular name in db). so, if such entry present, go inside if
, otherwise was
remains zero. finally, was
returned.
public int washere(string name, string date) throws sqlexception { log.d("washere", "begins, date = " + date); cursor c = ourdatabase.query(database_table, all_keys, key_name + "=" + "'" + name + "'" + " , " + key_date + "=" + "'" + date + "'", null, null, null, null); log.d("washere", "below cursor"); int = 0; if(c.movetofirst()) { log.d("washere", "inside if"); = c.getint(c.getcolumnindex(key_was)); } lod.d("washere", "ends"); return was; }
from log entries, pasting particular ones (you can ignore time between "begins" , "ends" depends on loop calling washere
):
07-18 07:08:03.398: d/dbwas(29568): begins, date = 08 aug 2013 07-18 07:08:03.398: d/dbwas(29568): below cursor 07-18 07:08:03.398: d/dbwas(29568): ends 07-18 07:08:03.398: d/dbwas(29568): begins, date = 09 aug 2013 07-18 07:08:03.406: d/dbwas(29568): below cursor 07-18 07:08:03.406: d/dbwas(29568): ends 07-18 07:08:03.359: d/dbwas(29568): begins, date = 02 aug 2013 07-18 07:08:03.359: d/dbwas(29568): below cursor 07-18 07:08:03.367: d/dbwas(29568): inside if 07-18 07:08:03.367: d/dbwas(29568): ends 07-18 07:08:03.367: d/dbwas(29568): begins, date = 03 aug 2013 07-18 07:08:03.367: d/dbwas(29568): below cursor 07-18 07:08:03.375: d/dbwas(29568): inside if 07-18 07:08:03.375: d/dbwas(29568): ends 07-18 07:08:03.430: d/dbwas(29568): begins, date = 14 aug 2013 07-18 07:08:03.430: d/dbwas(29568): below cursor 07-18 07:08:03.430: d/dbwas(29568): inside if 07-18 07:08:03.430: d/dbwas(29568): ends
my question regarding log times "begins" , "ends". can see above, among 5 log entries, 2 (8 aug , 14 aug) take 0 time "begins, date = ..." "ends".
9 aug takes 8 ms (.008 seconds) in executing cursor
statement.
2 aug , 3 aug take 8 ms (.008 seconds) in executing if
statement.
14 aug takes no time executing either of 2 above mentioned statements.
similarly, there many such discrepancies in "log". different dates, cursor
, if
statements randomly take 8 ms (and yes, time 8 ms).
now, executing "washere" method hundreds of times, hundreds of 8 milliseconds cost me time. why above discrepancies happening randomly. , there way remove (or maybe way of doing doing). [8 aug , 14 aug statement take 0 time should.]
on system, timer interrupt apparently runs @ 125 hz , happens every 8 ms. if function gets executed between 2 timer interrupts, see no change in timestamps, if timer interrupt happens while function executing, see jump of 8 ms.
there no discrepancy in actual execution times; timestamps in log not precise enough.
Comments
Post a Comment