I am new to Rust and I am trying to read 2,000,000 database postgresql with Rust.
The same code takes 8 seconds in Java but with Rust it takes about 50 seconds.
I am sure doing something wrong. (Postgres 0.18.1 - Rust 1.49.0-nightly)
Here is the code:
{
let url = "postgresql://user:pass@localhost:5432/mydb";
let client = Client::connect(url, NoTls).unwrap();
client
}
pub fn get_entries(mut client: Client)->(i32, Vec<Res1>)
{
let mut count= 0;
let mut res = Vec::new();
for row in client.query("SELECT * FROM data", &[]).unwrap()
{
//println!("{:?}", row);
let r = Res1 {
index: row.get(0),
mdate: row.get(1),
mtime: row.get(2),
bid: row.get(3),
ask: row.get(4),
last: row.get(5),
volume: row.get(6),
};
res.push(r);
count += 1;
}
(count, res)
}
Many readers of this forum will ignore code snippets, compiler error reports, etc that do not follow the posting guidelines for new contributors that are pinned to the top of this forum. Even those who do respond may feel that the lack of following the forum posting guidelines is disrespectful of their time. Thanks.
When comparing timing of Rust code vs. other languages, always run rustc in release mode, not in the default debug mode. It is not uncommon for debug-mode code to run 10x to 100x slower than release mode. There are dozens of threads in this forum about timing Rust code and optimizing performance; all of them start with the warning to not test debug-mode code.
I won't look at the code, but the usual first question coming up is, did you compile with --release option? I don't know what the library does under the hood, so it's unclear to me how debug/release mode affects performance for this particular case.