1

I am using SQLite in my mobile application to collect data from a sensor using Bluetooth Low Energy. Sensor is sending values every second. The approach I used is like this: When new data is received, I read it and insert it into a table in the database. The problem is: I noticed that the application crashes when it reaches 1500 insertion. My question is:

In term of performance, is it better to insert one value per second (the approach I am using today) or to collect 60 values in a array variable then insert them in one transaction ?

Is there any other way to optimize the performance of SQLite ? I need to keep the application running the whole day. That's 86400 values to be stored

Pryda
  • 899
  • 5
  • 14
  • 37
  • 1
    1 per sec VS 1 per min is not much difference in performance. It takes couple milliseconds to insert (if done right). `the application crashes when it reaches 1500 insertion` with which exception and on which lines of code? `Is there any other way to optimize the performance` we can't say as you didn't show your way. – Vladyslav Matviienko Sep 20 '19 at 11:05
  • @TimBiegeleisen I don't think he is using network at all, he is using SQLite – Vladyslav Matviienko Sep 20 '19 at 11:06
  • @VladyslavMatviienko I missed that `:-(` ... what I said might still hold, but not to the same degree, so I have deleted my comment. – Tim Biegeleisen Sep 20 '19 at 11:06

1 Answers1

1

Taken from this answer:

Which is faster: multiple single INSERTs or one multiple-row INSERT?

The time required for inserting a row is determined by the following factors, where the numbers indicate approximate proportions:

  • Connecting: (3)
  • Sending query to server: (2)
  • Parsing query: (2)
  • Inserting row: (1 × size of row)
  • Inserting indexes: (1 × number of indexes)
  • Closing: (1)

In conlcusion, sending one query for 60 entries every minute is many times faster than sending a query every second.

Gerke
  • 926
  • 1
  • 10
  • 20