Set up Sqlite3 sensor.db

Native GCC & C and Sqlite3

nano /mnt/sda1/opendb.c
#include <stdio.h>
#include <sqlite3.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char* argv[])
{
   sqlite3 *db;
   sqlite3_stmt    *res;
   int rc;
   const char      *tail;
   int i;
   clock_t tic = clock();
   for(i = 0; i < 1000; i++) {
   rc = sqlite3_open("/root/sensor.db", &db);
   if( rc ){
      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      exit(0);
   }else{
//      fprintf(stderr, "Opened database successfully\n");
   }
   rc = sqlite3_prepare_v2(db,"select temperature from sensor_data limit 1", 1000, &res, &tail);
   while (sqlite3_step(res) == SQLITE_ROW) {
//      printf("%s\n", sqlite3_column_text(res, 0));
   }
   sqlite3_finalize(res);
   sqlite3_close(db);
   }
   clock_t toc = clock();
   printf("Elapsed: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC);
   return 0;
}
cd /mnt/sda1
gcc -o opendb opendb.c -lsqlite3 -ldl -lpthread
./opendb
Elapsed: 3.590000 seconds



Speed is 3.59 ms

 

Comments powered by CComment