add initial zad3
This commit is contained in:
parent
e791acc2fe
commit
772d49043d
16 changed files with 553 additions and 0 deletions
2
lab3/zad3/.gitignore
vendored
Normal file
2
lab3/zad3/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
target/
|
||||
results/
|
293
lab3/zad3/Cargo.lock
generated
Normal file
293
lab3/zad3/Cargo.lock
generated
Normal file
|
@ -0,0 +1,293 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d"
|
||||
dependencies = [
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
|
||||
|
||||
[[package]]
|
||||
name = "dashmap"
|
||||
version = "5.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"hashbrown",
|
||||
"lock_api",
|
||||
"once_cell",
|
||||
"parking_lot_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.153"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||
|
||||
[[package]]
|
||||
name = "libgen"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libselect"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"libsort",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsort"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot_core"
|
||||
version = "0.9.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
|
||||
dependencies = [
|
||||
"either",
|
||||
"rayon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon-core"
|
||||
version = "1.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
|
||||
dependencies = [
|
||||
"crossbeam-deque",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.13.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
||||
|
||||
[[package]]
|
||||
name = "zad2"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"dashmap",
|
||||
"libgen",
|
||||
"libselect",
|
||||
"rayon",
|
||||
]
|
10
lab3/zad3/Cargo.toml
Normal file
10
lab3/zad3/Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "zad2"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
libgen = { path = "../../libgen" }
|
||||
libselect = { path = "../../libselect" }
|
||||
rayon = "1.10.0"
|
||||
dashmap = "5.5.3"
|
14
lab3/zad3/gnuplot/comp.gp
Normal file
14
lab3/zad3/gnuplot/comp.gp
Normal file
|
@ -0,0 +1,14 @@
|
|||
set title "Average comparisons, n ∈ {100, 200, ..., 50000}"
|
||||
set style data lines
|
||||
|
||||
set xlabel "n"
|
||||
set ylabel "Average comparisons"
|
||||
set term pdfcairo font "JetBrainsMono-NF,12"
|
||||
|
||||
plot "./results/result" \
|
||||
using 1:2 t "Select 3", \
|
||||
"" using 1:5 t "Select 5", \
|
||||
"" using 1:8 t "Select 7", \
|
||||
"" using 1:11 t "Select 9"
|
||||
|
||||
# vim: ft=gnuplot
|
14
lab3/zad3/gnuplot/comp_n.gp
Normal file
14
lab3/zad3/gnuplot/comp_n.gp
Normal file
|
@ -0,0 +1,14 @@
|
|||
set title "Average comparisons / n, n ∈ {100, 200, ..., 50000}"
|
||||
set style data lines
|
||||
|
||||
set xlabel "n"
|
||||
set ylabel "Average comparisons / n"
|
||||
set term pdfcairo font "JetBrainsMono-NF,12"
|
||||
|
||||
plot "./results/result" \
|
||||
using 1:14 t "Select 3", \
|
||||
"" using 1:17 t "Select 5", \
|
||||
"" using 1:20 t "Select 7", \
|
||||
"" using 1:23 t "Select 9"
|
||||
|
||||
# vim: ft=gnuplot
|
14
lab3/zad3/gnuplot/swap.gp
Normal file
14
lab3/zad3/gnuplot/swap.gp
Normal file
|
@ -0,0 +1,14 @@
|
|||
set title "Average swaps, n ∈ {100, 200, ..., 50000}"
|
||||
set style data lines
|
||||
|
||||
set xlabel "n"
|
||||
set ylabel "Average swaps"
|
||||
set term pdfcairo font "JetBrainsMono-NF,12"
|
||||
|
||||
plot "./results/result" \
|
||||
using 1:3 t "Select 3", \
|
||||
"" using 1:6 t "Select 5", \
|
||||
"" using 1:9 t "Select 7", \
|
||||
"" using 1:12 t "Select 9"
|
||||
|
||||
# vim: ft=gnuplot
|
14
lab3/zad3/gnuplot/swap_n.gp
Normal file
14
lab3/zad3/gnuplot/swap_n.gp
Normal file
|
@ -0,0 +1,14 @@
|
|||
set title "Average swaps / n, n ∈ {100, 200, ..., 50000}"
|
||||
set style data lines
|
||||
|
||||
set xlabel "n"
|
||||
set ylabel "Average swaps / n"
|
||||
set term pdfcairo font "JetBrainsMono-NF,12"
|
||||
|
||||
plot "./results/result" \
|
||||
using 1:15 t "Select 3", \
|
||||
"" using 1:18 t "Select 5", \
|
||||
"" using 1:21 t "Select 7", \
|
||||
"" using 1:24 t "Select 9"
|
||||
|
||||
# vim: ft=gnuplot
|
14
lab3/zad3/gnuplot/time.gp
Normal file
14
lab3/zad3/gnuplot/time.gp
Normal file
|
@ -0,0 +1,14 @@
|
|||
set title "Average time, n ∈ {100, 200, ..., 50000}"
|
||||
set style data lines
|
||||
|
||||
set xlabel "n"
|
||||
set ylabel "Average time"
|
||||
set term pdfcairo font "JetBrainsMono-NF,12"
|
||||
|
||||
plot "./results/result" \
|
||||
using 1:4 t "Select 3", \
|
||||
"" using 1:7 t "Select 5", \
|
||||
"" using 1:10 t "Select 7", \
|
||||
"" using 1:13 t "Select 9"
|
||||
|
||||
# vim: ft=gnuplot
|
14
lab3/zad3/gnuplot/time_n.gp
Normal file
14
lab3/zad3/gnuplot/time_n.gp
Normal file
|
@ -0,0 +1,14 @@
|
|||
set title "Average time / n, n ∈ {100, 200, ..., 50000}"
|
||||
set style data lines
|
||||
|
||||
set xlabel "n"
|
||||
set ylabel "Average time / n"
|
||||
set term pdfcairo font "JetBrainsMono-NF,12"
|
||||
|
||||
plot "./results/result" \
|
||||
using 1:16 t "Select 3", \
|
||||
"" using 1:19 t "Select 5", \
|
||||
"" using 1:22 t "Select 7", \
|
||||
"" using 1:25 t "Select 9"
|
||||
|
||||
# vim: ft=gnuplot
|
BIN
lab3/zad3/plots/comp.pdf
Normal file
BIN
lab3/zad3/plots/comp.pdf
Normal file
Binary file not shown.
BIN
lab3/zad3/plots/comp_n.pdf
Normal file
BIN
lab3/zad3/plots/comp_n.pdf
Normal file
Binary file not shown.
BIN
lab3/zad3/plots/swap.pdf
Normal file
BIN
lab3/zad3/plots/swap.pdf
Normal file
Binary file not shown.
BIN
lab3/zad3/plots/swap_n.pdf
Normal file
BIN
lab3/zad3/plots/swap_n.pdf
Normal file
Binary file not shown.
BIN
lab3/zad3/plots/time.pdf
Normal file
BIN
lab3/zad3/plots/time.pdf
Normal file
Binary file not shown.
BIN
lab3/zad3/plots/time_n.pdf
Normal file
BIN
lab3/zad3/plots/time_n.pdf
Normal file
Binary file not shown.
164
lab3/zad3/src/main.rs
Normal file
164
lab3/zad3/src/main.rs
Normal file
|
@ -0,0 +1,164 @@
|
|||
use std::{fs::{self, OpenOptions}, io::{self, Write}, sync::Arc, time::SystemTime};
|
||||
|
||||
use dashmap::DashMap;
|
||||
use libgen::gen_rand;
|
||||
use libselect::normal_select::NormalSelect;
|
||||
use libselect::Select;
|
||||
use rayon::{current_thread_index, iter::{IntoParallelIterator, ParallelIterator}};
|
||||
|
||||
fn comp_avg(results_map: &DashMap<u64, Vec<(u64, u64, u128)>>) -> DashMap<u64, f64> {
|
||||
results_map.iter()
|
||||
.map(|ref_multi| {
|
||||
let (i, results) = ref_multi.pair();
|
||||
(*i, (results.iter()
|
||||
.map(|res| res.0)
|
||||
.sum::<u64>() as f64 / results.len() as f64))
|
||||
}
|
||||
)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn swap_avg(results_map: &DashMap<u64, Vec<(u64, u64, u128)>>) -> DashMap<u64, f64> {
|
||||
results_map.iter()
|
||||
.map(|ref_multi| {
|
||||
let (i, results) = ref_multi.pair();
|
||||
(*i, (results.iter()
|
||||
.map(|res| res.1)
|
||||
.sum::<u64>() as f64 / results.len() as f64))
|
||||
}
|
||||
)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn time_avg(results_map: &DashMap<u64, Vec<(u64, u64, u128)>>) -> DashMap<u64, f64> {
|
||||
results_map.iter()
|
||||
.map(|ref_multi| {
|
||||
let (i, results) = ref_multi.pair();
|
||||
(*i, (results.iter()
|
||||
.map(|res| res.2)
|
||||
.sum::<u128>() as f64 / results.len() as f64))
|
||||
}
|
||||
)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
|
||||
let m = 50;
|
||||
|
||||
let select_3_results: Arc<DashMap<u64, Vec<(u64, u64, u128)>>> = Arc::new(DashMap::new());
|
||||
let select_5_results: Arc<DashMap<u64, Vec<(u64, u64, u128)>>> = Arc::new(DashMap::new());
|
||||
let select_7_results: Arc<DashMap<u64, Vec<(u64, u64, u128)>>> = Arc::new(DashMap::new());
|
||||
let select_9_results: Arc<DashMap<u64, Vec<(u64, u64, u128)>>> = Arc::new(DashMap::new());
|
||||
|
||||
let select_3_results_clone = Arc::clone(&select_3_results);
|
||||
let select_5_results_clone = Arc::clone(&select_5_results);
|
||||
let select_7_results_clone = Arc::clone(&select_7_results);
|
||||
let select_9_results_clone = Arc::clone(&select_9_results);
|
||||
|
||||
(100u64..=50000u64).step_by(100).collect::<Vec<_>>().into_par_iter().for_each(move |n| {
|
||||
if select_3_results_clone.get(&n).is_some() {
|
||||
return;
|
||||
}
|
||||
if select_5_results_clone.get(&n).is_some() {
|
||||
return;
|
||||
}
|
||||
if select_7_results_clone.get(&n).is_some() {
|
||||
return;
|
||||
}
|
||||
if select_9_results_clone.get(&n).is_some() {
|
||||
return;
|
||||
}
|
||||
println!("{}: starting n: {n}", current_thread_index().unwrap());
|
||||
let input = gen_rand(n);
|
||||
|
||||
select_3_results_clone.insert(n, vec![]);
|
||||
select_5_results_clone.insert(n, vec![]);
|
||||
select_7_results_clone.insert(n, vec![]);
|
||||
select_9_results_clone.insert(n, vec![]);
|
||||
|
||||
let mut select_3 = NormalSelect::new(false);
|
||||
let mut select_5 = NormalSelect::new(false);
|
||||
let mut select_7 = NormalSelect::new(false);
|
||||
let mut select_9 = NormalSelect::new(false);
|
||||
|
||||
let k = n as usize / 2;
|
||||
for _ in 0..m {
|
||||
_ = std::io::stdout().flush();
|
||||
let time_3 = SystemTime::now();
|
||||
select_3.select_k(&input, k, 3);
|
||||
let time_3 = time_3.elapsed().unwrap().as_millis();
|
||||
let time_5 = SystemTime::now();
|
||||
select_5.select_k(&input, k, 5);
|
||||
let time_5 = time_5.elapsed().unwrap().as_millis();
|
||||
let time_7 = SystemTime::now();
|
||||
select_7.select_k(&input, k, 7);
|
||||
let time_7 = time_7.elapsed().unwrap().as_millis();
|
||||
let time_9 = SystemTime::now();
|
||||
select_9.select_k(&input, k, 9);
|
||||
let time_9 = time_9.elapsed().unwrap().as_millis();
|
||||
|
||||
select_3_results_clone.get_mut(&n).unwrap().push((select_3.num_comp(), select_3.num_swap(), time_3));
|
||||
select_5_results_clone.get_mut(&n).unwrap().push((select_5.num_comp(), select_5.num_swap(), time_5));
|
||||
select_7_results_clone.get_mut(&n).unwrap().push((select_7.num_comp(), select_7.num_swap(), time_7));
|
||||
select_9_results_clone.get_mut(&n).unwrap().push((select_9.num_comp(), select_9.num_swap(), time_9));
|
||||
}
|
||||
println!("{}: finished n: {n}", current_thread_index().unwrap());
|
||||
});
|
||||
|
||||
let select_3_comp_averages = comp_avg(&select_3_results);
|
||||
let select_3_swap_averages = swap_avg(&select_3_results);
|
||||
let select_3_time_averages = time_avg(&select_3_results);
|
||||
|
||||
let select_5_comp_averages = comp_avg(&select_5_results);
|
||||
let select_5_swap_averages = swap_avg(&select_5_results);
|
||||
let select_5_time_averages = time_avg(&select_5_results);
|
||||
|
||||
let select_7_comp_averages = comp_avg(&select_7_results);
|
||||
let select_7_swap_averages = swap_avg(&select_7_results);
|
||||
let select_7_time_averages = time_avg(&select_7_results);
|
||||
|
||||
let select_9_comp_averages = comp_avg(&select_9_results);
|
||||
let select_9_swap_averages = swap_avg(&select_9_results);
|
||||
let select_9_time_averages = time_avg(&select_9_results);
|
||||
|
||||
|
||||
_ = fs::create_dir_all("./results");
|
||||
|
||||
let mut results_file = OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.open(format!("./results/result"))?;
|
||||
|
||||
for n in (100..=50000).step_by(100) {
|
||||
writeln!(results_file, "{n} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}",
|
||||
select_3_comp_averages.get(&n).unwrap().value(),
|
||||
select_3_swap_averages.get(&n).unwrap().value(),
|
||||
select_3_time_averages.get(&n).unwrap().value(),
|
||||
select_5_comp_averages.get(&n).unwrap().value(),
|
||||
select_5_swap_averages.get(&n).unwrap().value(),
|
||||
select_5_time_averages.get(&n).unwrap().value(),
|
||||
select_7_comp_averages.get(&n).unwrap().value(),
|
||||
select_7_swap_averages.get(&n).unwrap().value(),
|
||||
select_7_time_averages.get(&n).unwrap().value(),
|
||||
select_9_comp_averages.get(&n).unwrap().value(),
|
||||
select_9_swap_averages.get(&n).unwrap().value(),
|
||||
select_9_time_averages.get(&n).unwrap().value(),
|
||||
select_3_comp_averages.get(&n).unwrap().value() / n as f64,
|
||||
select_3_swap_averages.get(&n).unwrap().value() / n as f64,
|
||||
select_3_time_averages.get(&n).unwrap().value() / n as f64,
|
||||
select_5_comp_averages.get(&n).unwrap().value() / n as f64,
|
||||
select_5_swap_averages.get(&n).unwrap().value() / n as f64,
|
||||
select_5_time_averages.get(&n).unwrap().value() / n as f64,
|
||||
select_7_comp_averages.get(&n).unwrap().value() / n as f64,
|
||||
select_7_swap_averages.get(&n).unwrap().value() / n as f64,
|
||||
select_7_time_averages.get(&n).unwrap().value() / n as f64,
|
||||
select_9_comp_averages.get(&n).unwrap().value() / n as f64,
|
||||
select_9_swap_averages.get(&n).unwrap().value() / n as f64,
|
||||
select_9_time_averages.get(&n).unwrap().value() / n as f64,
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in a new issue