Skip to content

Commit

Permalink
wip: blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
oneofthezombies committed Feb 12, 2024
1 parent 60b8a13 commit 6ea8a8e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 104 deletions.
8 changes: 4 additions & 4 deletions crates/apps/kill_tree_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ clap = { version = "4.4.18", features = ["derive", "cargo"] }
tokio = { version = "1.36.0", features = ["full"] }

[[bin]]
name = "tokio"
path = "src/tokio.rs"
name = "kill_tree_tokio"
path = "src/kill_tree_tokio.rs"

[[bin]]
name = "blocking"
path = "src/blocking.rs"
name = "kill_tree_blocking"
path = "src/kill_tree_blocking.rs"
File renamed without changes.
File renamed without changes.
87 changes: 0 additions & 87 deletions crates/apps/kill_tree_cli/src/main.rs

This file was deleted.

File renamed without changes.
32 changes: 19 additions & 13 deletions test.mjs → tests/resources/bench/test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spawn } from "child_process";

async function main() {
async function test(appName) {
const port = 50000;
const elapseds = [];
for (let i = 0; i < 1000; i++) {
Expand All @@ -14,12 +14,9 @@ async function main() {
target.on("spawn", () => {
console.log(`Spawned server ${target.pid}`);
const start = Date.now();
const kill_tree = spawn("target/release/blocking.exe", [target.pid], {
const kill_tree = spawn(`target/release/${appName}`, [target.pid], {
stdio: "inherit",
});
// const kill_tree = spawn("taskkill", ["/T", "/F", "/PID", target.pid], {
// stdio: "inherit",
// });
kill_tree.on("exit", () => {
const end = Date.now();
const elapsed = end - start;
Expand All @@ -33,8 +30,21 @@ async function main() {

const total = elapseds.reduce((a, b) => a + b, 0);
const mean = total / elapseds.length;
console.log(`Total elapsed time: ${total}ms`);
console.log(`Mean elapsed time: ${mean}ms`);
return {
total,
mean,
};
}

async function main() {
const blockingResult = await test("kill_tree_blocking");
const tokioResult = await test("kill_tree_tokio");
console.log(
`blocking: total: ${blockingResult.total}ms, mean: ${blockingResult.mean}ms`
);
console.log(
`tokio: total: ${tokioResult.total}ms, mean: ${tokioResult.mean}ms`
);
}

main();
Expand All @@ -59,9 +69,5 @@ main();
// Mean elapsed time: 6.291ms

// macos
// blocking
// Total elapsed time: 3724ms
// Mean elapsed time: 3.724ms
// tokio
// Total elapsed time: 4089ms
// Mean elapsed time: 4.089ms
// blocking: total: 3641ms, mean: 3.641ms
// tokio: total: 4232ms, mean: 4.232ms

0 comments on commit 6ea8a8e

Please sign in to comment.