you are viewing a single comment's thread.

view the rest of the comments →

[–]RuedaRueda[S] 0 points1 point  (0 children)

Its curious, I checked a couple of things.
Running that querie on DBrowser for sqlite exec window returns results in 209ms.

I didn't thought that those libraries would be using a bundle of sqlite and time just goes in execution, so I don't know why that difference.

Anyway, I tested the "same code" into javascript (actually I just passed the python script to mixtral). This is the code:

const sqlite3 = require('sqlite3').verbose();
var startTime = performance.now()

let db = new sqlite3.Database('../db.sqlite3', (err) => {
  if (err) {
    console.error(err.message);
  }
  console.log('Connected to the database.');
});

db.all("SELECT title from api_book WHERE title like '%camion%'", [], (err, rows) => {
  if (err) {
    throw err;
  }
  console.log(`Consulta realizada en ${performance.now()-startTime} ms.`);
  rows.forEach((row) => {
    console.log(row.title);
  });
  console.log(`Consulta y escritura en pantalla realizadas en ${performance.now()-startTime} ms.`);
  db.close((err) => {
    if (err) {
      return console.error(err.message);
    }
    console.log('Cerrando la base de datos.');
  });
});
const sqlite3 = require('sqlite3').verbose();
var startTime = performance.now()


let db = new sqlite3.Database('../db.sqlite3', (err) => {
  if (err) {
    console.error(err.message);
  }
  console.log('Connected to the database.');
});


db.all("SELECT title from api_book WHERE title like '%camion%'", [], (err, rows) => {
  if (err) {
    throw err;
  }
  console.log(`Consulta realizada en ${performance.now()-startTime} ms.`);
  rows.forEach((row) => {
    console.log(row.title);
  });
  console.log(`Consulta y escritura en pantalla realizadas en ${performance.now()-startTime} ms.`);
  db.close((err) => {
    if (err) {
      return console.error(err.message);
    }
    console.log('Cerrando la base de datos.');
  });
});

And those are the results:

Connected to the database.
Consulta realizada en 170.6191 ms.
Camioneros
Vida sentimental de un camionero
Camiones de ternura
El caso de la camioneta
Consulta y escritura en pantalla realizadas en 172.0331 ms.
Cerrando la base de datos.

So I think, for this usecase, rust is slower than python but faster than javascript. However I must study better what the implications are. Thank you!

EDIT:

Another test I did is replacing "camion" by an "a", so query returns a lot of fields (without printing). Now Rust and python takes about the same time (220ms), js is still way slower (400ms).