mirror of
https://github.com/denoland/deno.git
synced 2024-11-23 15:16:54 -05:00
31f32ed8c4
All benchmarks are done in Rust and can be invoked with `cargo bench`. Currently this has it's own "harness" that behaves like `./tools/benchmark.py` did. Because of this tests inside `cli/bench` are currently not run. This should be switched to the language provided harness once the `#[bench]` attribute has been stabilized.
62 lines
1.6 KiB
Rust
62 lines
1.6 KiB
Rust
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
use super::Result;
|
|
use serde_json::{Number, Value};
|
|
use std::{
|
|
path::PathBuf,
|
|
process::Command,
|
|
time::{Duration, Instant},
|
|
};
|
|
|
|
const MB: usize = 1024 * 1024;
|
|
const SERVER_ADDR: &str = "0.0.0.0:4544";
|
|
const CLIENT_ADDR: &str = "127.0.0.1 4544";
|
|
|
|
pub(crate) fn cat(deno_exe: &PathBuf, megs: usize) -> Result<Value> {
|
|
let size = megs * MB;
|
|
let shell_cmd = format!(
|
|
"{} run --allow-read cli/tests/cat.ts /dev/zero | head -c {}",
|
|
deno_exe.to_str().unwrap(),
|
|
size
|
|
);
|
|
println!("{}", shell_cmd);
|
|
let cmd = &["sh", "-c", &shell_cmd];
|
|
|
|
let start = Instant::now();
|
|
let _ = test_util::run_collect(cmd, None, None, None, true);
|
|
let end = Instant::now();
|
|
|
|
Ok(Value::Number(
|
|
Number::from_f64((end - start).as_secs_f64()).unwrap(),
|
|
))
|
|
}
|
|
|
|
pub(crate) fn tcp(deno_exe: &PathBuf, megs: usize) -> Result<Value> {
|
|
let size = megs * MB;
|
|
|
|
let shell_cmd = format!("head -c {} /dev/zero | nc {}", size, CLIENT_ADDR);
|
|
println!("{}", shell_cmd);
|
|
let cmd = &["sh", "-c", &shell_cmd];
|
|
|
|
// Run deno echo server in the background.
|
|
let mut echo_server = Command::new(deno_exe.to_str().unwrap())
|
|
.args(&[
|
|
"run",
|
|
"--allow-net",
|
|
"cli/tests/echo_server.ts",
|
|
SERVER_ADDR,
|
|
])
|
|
.spawn()?;
|
|
|
|
std::thread::sleep(Duration::from_secs(5)); // wait for deno to wake up. TODO racy.
|
|
|
|
let start = Instant::now();
|
|
let _ = test_util::run_collect(cmd, None, None, None, true);
|
|
let end = Instant::now();
|
|
|
|
echo_server.kill()?;
|
|
|
|
Ok(Value::Number(
|
|
Number::from_f64((end - start).as_secs_f64()).unwrap(),
|
|
))
|
|
}
|