Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8245703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:16:24+00:00 2026-06-07T22:16:24+00:00

I am measuring the execution time of methods that open and close a database,

  • 0

I am measuring the execution time of methods that open and close a database, as well as performing a query and an insert on it. For each one of these four operations I basically get the time before and after the execution of the relevant statement like this:

for(int i = 0; i < 500; i++) {
    startTime = System.nanoTime();
    long insertResult = db.insert(tableName, null, contentValues);
    endTime = System.nanoTime();
    if(insertResult > -1) {
        generateNoteOnSD(fileName, (endTime - startTime));
    }
}

In the case of the insert:

  • The minimum execution time in the sample is 13 ms (milliseconds)
  • The maximum execution time in the sample is 537 ms
  • A little bit more than 50% of the results set (259 ‘insert’ executions from the 500) are between 15 and 20 ms.
  • Values above 20 ms have a very low frequency (1, 2 or 3).

Could somebody please give me an idea/direction on how this type of operations are performed by the system? I do not really know how a write operation to persisten storage is done and on what factors does it depend. I want to know this to trying to explain the above described measurements (why the variation on the execution times for the same operation).

Any help is very appreciated.

Octavio

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:16:27+00:00Added an answer on June 7, 2026 at 10:16 pm

    I will assume that this is a regular table, not a temp table.

    Let us start by the biggest performance hog here.

    By default, each such insert starts and ends a new transaction. If you want to speed this up tremendously, apply

    db.beginTransaction();
    

    before your loop, and

    db.setTransactionSuccessful();
    db.endTransaction;
    

    after the loop. This will put all the inserts in the same transaction. Be sure to measure the time of db.endTransaction where some of the total time spent will have moved. When you did not call these operations by hand, each db.insert was implicitly wrapped in those anyway, and this is called implicit transactions.

    While the transactioning protocol itself is complex and accounts for some of the performance difference, the fine grained transactions entail a difference in hardware speed. Transactions need to be durable, so they entail writes to the flash memory (writes are even slower than reads, and you need more than one write per transaction). In contrast, the “one long transaction” writes to volatile memory, and even though the data needs to go to the flash during the commit as well, you will only need a fraction of the writes. This effect is clearer if your rows are narrow, because more rows will fit into a flash memory block and be written at once.

    As far as reads go, transactioning plays less of a role here. It is easy. If your application is hot in the volatile RAM, all the data goes from there. If it is not, the data goes from the flash.

    The spike in your data may well be attributable to unrelated background processes competing with the database. This would occur only when those applications do intensive computation. If some of those processes access the same database, you could also be experience lock contention; this is possible even if those processes are waiting for something else. This would also explain why their distribution is so irregular. This is not the only possibility.

    For a general overview of the algorithms used in SQLite, it may be useful to look at this book, although it has been written for a competing operating system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For measuring execution time of methods, I've seen suggestions to use public class PerformanceInterceptor
How can I measure the execution time of a query without measuring the time
I have found some code on measuring execution time here http://www.dreamincode.net/forums/index.php?showtopic=24685 However, it does
I wanna measure the performance to my database by measuring the time taken to
I have a problem with time measuring that's really bothering me. I am executing
Ok, I have this basics PHP logic made for measuring execution time in PHP,
I just came across this post that talks about time measuring. I remember (I
I try to use joda-time library for easier measuring the execution time of my
I know that System.nanoTime() is now the preferred method for measuring time over System.currentTimeInMillis()
I found an example of QueryPerformanceCounter, http://advancedcppwithexamples.blogspot.com/2009/08/measuring-elapsed-time-in-c-using_21.html The example measures a sleep of 100ms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.