Upload of Latency testing code for the sakila test database in MySQL
This commit is contained in:
parent
a41cb539a3
commit
adb0dddb59
45
.vscode/launch.json
vendored
Normal file
45
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug executable 'sql_load_test'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"build",
|
||||
"--bin=sql_load_test",
|
||||
"--package=sql_load_test"
|
||||
],
|
||||
"filter": {
|
||||
"name": "sql_load_test",
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug unit tests in executable 'sql_load_test'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"test",
|
||||
"--no-run",
|
||||
"--bin=sql_load_test",
|
||||
"--package=sql_load_test"
|
||||
],
|
||||
"filter": {
|
||||
"name": "sql_load_test",
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "sql_latency_test"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
mysql = "24.0.0"
|
31
src/main.rs
Normal file
31
src/main.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use std::time::{SystemTime, Duration};
|
||||
|
||||
use mysql::*;
|
||||
use mysql::prelude::*;
|
||||
|
||||
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||
//Create a connection pool
|
||||
let url = "mysql://sakila:p_ssW0rd@localhost:3306/sakila";
|
||||
let pool = Pool::new(url)?;
|
||||
let mut conn = pool.get_conn()?;
|
||||
|
||||
//Outline the number of queries and mark the start time.
|
||||
const NUMQUERIES: u32 = 5_000;
|
||||
let mut times: Vec<(u32, Duration)> = vec![];
|
||||
let start_time = SystemTime::now();
|
||||
|
||||
// Run the Query, NUM_QUERIES times
|
||||
for i in 0..NUMQUERIES {
|
||||
let start_query = SystemTime::now();
|
||||
let _ = conn.query_drop(r"SELECT release_year, COUNT(*) FROM sakila.film INNER JOIN (SELECT DISTINCT release_year FROM sakila.film) release_years USING (release_year) GROUP BY release_year;")?;
|
||||
times.push((i, SystemTime::now().duration_since(start_query).unwrap()))
|
||||
}
|
||||
|
||||
//Output results
|
||||
println!("Total execution time: {}s", SystemTime::now().duration_since(start_time).unwrap().as_secs_f32());
|
||||
for (query_id, duration) in times.iter() {
|
||||
println!("{}: {}.{} milliseconds", query_id, duration.as_millis(), duration.as_micros());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue
Block a user