From 1e8af7676ba840e3f401f09b3e0d19231eca6f45 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Mon, 6 Apr 2020 11:24:13 +0200 Subject: [PATCH] Add measuring of goroutines from the may crate --- Cargo.lock | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 +- src/main.rs | 7 ++ src/to_bench.rs | 21 ++++++ 4 files changed, 202 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index f00acee..f1f9a43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,17 +23,44 @@ dependencies = [ "benchlib-rs", "crossbeam-channel", "crossbeam-utils", + "may", "num-traits", "num_cpus", "rayon", ] +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "cc" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" + [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "crossbeam" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69323bff1fb41c635347b8ead484a5ca6c3f11914d784170b158d8449ab07f8e" +dependencies = [ + "cfg-if", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + [[package]] name = "crossbeam-channel" version = "0.4.2" @@ -97,6 +124,19 @@ version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +[[package]] +name = "generator" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caaa160efb38ce00acbe4450d41a103fb3d2acdb17ff09a7cf38f3ac26af0738" +dependencies = [ + "cc", + "libc", + "log", + "rustc_version", + "winapi", +] + [[package]] name = "hermit-abi" version = "0.1.10" @@ -118,6 +158,45 @@ version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0" +[[package]] +name = "log" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "may" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ec258004b51e3bb001d5fe1954400e149d9c0718c3a5445ff8c445f58d5dfe2" +dependencies = [ + "crossbeam", + "generator", + "libc", + "log", + "may_queue", + "miow", + "nix", + "num_cpus", + "rustc_version", + "smallvec", + "socket2", + "winapi", +] + +[[package]] +name = "may_queue" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f88ce6d67629aa46cc5dfa7fb1e831e3cd56b16a19c9362ead2832d19f126ae8" +dependencies = [ + "crossbeam", + "rustc_version", +] + [[package]] name = "maybe-uninit" version = "2.0.0" @@ -133,6 +212,29 @@ dependencies = [ "autocfg", ] +[[package]] +name = "miow" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226" +dependencies = [ + "socket2", + "winapi", +] + +[[package]] +name = "nix" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "void", +] + [[package]] name = "num-traits" version = "0.2.11" @@ -197,12 +299,54 @@ dependencies = [ "redox_syscall", ] +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "smallvec" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc" + +[[package]] +name = "socket2" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "winapi", +] + [[package]] name = "termion" version = "1.5.5" @@ -214,3 +358,31 @@ dependencies = [ "redox_syscall", "redox_termios", ] + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "winapi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index fca0ffb..fde3589 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,5 @@ crossbeam-channel = "0.4.2" benchlib-rs = "0.3.1" crossbeam-utils = "0.7.2" num_cpus = "1.0" -num-traits = "0.2.11" \ No newline at end of file +num-traits = "0.2.11" +may = "0.3.17" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 002de5c..633c3de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,9 +51,16 @@ pub fn main() { .set_iterations(1000) .print_settings() .bench("Spawn and stop thread", || to_bench::start_stop_thread()) + .bench("Start and stop coroutine", || { + to_bench::start_stop_coroutine() + }) + .compare() .bench("Start and stop threads==cpus", || { to_bench::start_and_wait_for_num_cpu_threads() }) + .bench("Start and stop coroutines==cpus", || { + to_bench::start_and_wait_for_num_cpu_coroutines() + }) .compare() .bench("MPSC channel transmit 1000x u128", || { to_bench::send_mpsc_channel() diff --git a/src/to_bench.rs b/src/to_bench.rs index f995c95..89cb14f 100644 --- a/src/to_bench.rs +++ b/src/to_bench.rs @@ -1,5 +1,6 @@ use crossbeam_channel::unbounded; use crossbeam_utils::sync::WaitGroup; +use may::go; use num_cpus; use num_traits::{PrimInt, Unsigned}; use rayon::prelude::*; @@ -16,6 +17,13 @@ pub fn start_stop_thread() { handle.join().unwrap(); } +pub fn start_stop_coroutine() { + let handle = go!(|| { + return; + }); + handle.join().unwrap(); +} + pub fn summation_to(end: T) -> T { let mut res: T = T::zero(); let mut i = T::zero(); @@ -126,6 +134,19 @@ pub fn start_and_wait_for_num_cpu_threads() { wg.wait(); } +pub fn start_and_wait_for_num_cpu_coroutines() { + let wg = WaitGroup::new(); + + for thread_number in 0..num_cpus::get() { + let wg = wg.clone(); + go!(move || { + std::mem::drop(wg); + thread_number + }); + } + wg.wait(); +} + pub fn max_f32_multiplication(times: usize) -> f64 { let mut result = 0f64; for _ in 0..times {