xiaoas
xiaoas2y ago

Following deno_core code execution is slower

So I have the following code, which is taken from https://github.com/denoland/deno/tree/main/core/examples and edited for simple benchmarking:
use std::time::Instant;

use deno_core::v8;
use deno_core::JsRuntime;
use deno_core::RuntimeOptions;

fn main() {
let mut runtime = JsRuntime::new(RuntimeOptions::default());

// Evaluate some code
let code = "let a = 1+4; a*2";
for _ in 0..10 {
let instant = Instant::now();
runtime.execute_script_static("<anon>", code);
println!("{:?}", instant.elapsed());
}
}
use std::time::Instant;

use deno_core::v8;
use deno_core::JsRuntime;
use deno_core::RuntimeOptions;

fn main() {
let mut runtime = JsRuntime::new(RuntimeOptions::default());

// Evaluate some code
let code = "let a = 1+4; a*2";
for _ in 0..10 {
let instant = Instant::now();
runtime.execute_script_static("<anon>", code);
println!("{:?}", instant.elapsed());
}
}
Which outputs the following:
28.809µs
321.455µs
181.944µs
132.383µs
128.343µs
121.826µs
119.734µs
114.393µs
131.579µs
162.282µs
28.809µs
321.455µs
181.944µs
132.383µs
128.343µs
121.826µs
119.734µs
114.393µs
131.579µs
162.282µs
the second run seems to be significantly slower than the first. Is this a performance bug? Or am I using the runtime incorrectly?
GitHub
deno/core/examples at main · denoland/deno
A modern runtime for JavaScript and TypeScript. Contribute to denoland/deno development by creating an account on GitHub.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?