diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f170a5b --- /dev/null +++ b/.vscode/launch.json @@ -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}" + } + ] +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a1daffa --- /dev/null +++ b/Cargo.toml @@ -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" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..ec91cf3 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,31 @@ +use std::time::{SystemTime, Duration}; + +use mysql::*; +use mysql::prelude::*; + +fn main() -> std::result::Result<(), Box> { + //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(()) +} \ No newline at end of file