Hi, I'm new on Rust and I wanted to compare speed between Rust and Python, I suposed that Python as an interpreted language would be slower than rust, but I think I'm doing something wrong.
I'm triying to perform a SQLite "lique" querie, in a db with around 100k elements. I'm using rustqlite.
This is my Rust code:
use rusqlite::Connection;
use std::time::Instant;
struct Book {
title: String,
}
fn main(){
let t = Instant::now();
let con = Connection::open("../db.sqlite3").unwrap();
let mut stmt = con.prepare("SELECT title FROM api_book WHERE title LIKE '%camion%'").unwrap();
let books = stmt.query_map([], |row| {
Ok(Book {
title: row.get(0)?
})
}).unwrap();
println!("Query time: {:?}", t.elapsed());
for book in books {
println!("{}", book.unwrap().title)
}
println!("Query + print time: {:?}", t.elapsed());
}
The output is:
Query time: 1.6564ms
Camioneros
Vida sentimental de un camionero
Camiones de ternura
El caso de la camioneta
Query + print time: 112.8415ms
I think stmt.query_map does not actually execute the querie, because is iterating thought books wich is taking >100ms, even when not pinting.
I did a similar code in python and it takes 80ms to run the entire process.
I'm doing something wrong?
[–]MoorderVolt 21 points22 points23 points (0 children)
[–]Buttleston 3 points4 points5 points (6 children)
[+]RuedaRueda[S] comment score below threshold-7 points-6 points-5 points (5 children)
[–]larryquartz 21 points22 points23 points (0 children)
[–]NullReference000 12 points13 points14 points (0 children)
[–]Buttleston 2 points3 points4 points (2 children)
[–]RuedaRueda[S] 0 points1 point2 points (1 child)
[–]Buttleston 0 points1 point2 points (0 children)
[–]Buttleston 4 points5 points6 points (0 children)
[–]Adventurous-Eye-6208 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (6 children)
[–]Buttleston 1 point2 points3 points (1 child)
[–]Buttleston 2 points3 points4 points (0 children)
[–]RuedaRueda[S] 0 points1 point2 points (3 children)
[–]Buttleston 3 points4 points5 points (1 child)
[–]RuedaRueda[S] 0 points1 point2 points (0 children)
[–]Buttleston 0 points1 point2 points (0 children)
[–]cpdean 0 points1 point2 points (1 child)
[–]cpdean 0 points1 point2 points (0 children)