mirror of
https://github.com/denoland/deno.git
synced 2024-12-01 16:51:13 -05:00
0cce9c2bcc
``` Benchmark 1: deno run -A ../empty.js Time (mean ± σ): 20.5 ms ± 0.5 ms [User: 13.4 ms, System: 5.1 ms] Range (min … max): 19.8 ms … 24.0 ms 119 runs Benchmark 2: target/release/deno run -A ../empty.js Time (mean ± σ): 18.8 ms ± 0.3 ms [User: 13.0 ms, System: 4.9 ms] Range (min … max): 18.3 ms … 19.9 ms 129 runs ``` --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
85 lines
2.7 KiB
Rust
85 lines
2.7 KiB
Rust
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
use deno_core::error::AnyError;
|
|
use deno_core::FsModuleLoader;
|
|
use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel;
|
|
use deno_runtime::deno_web::BlobStore;
|
|
use deno_runtime::permissions::PermissionsContainer;
|
|
use deno_runtime::worker::MainWorker;
|
|
use deno_runtime::worker::WorkerOptions;
|
|
use deno_runtime::BootstrapOptions;
|
|
use std::path::Path;
|
|
use std::rc::Rc;
|
|
use std::sync::Arc;
|
|
|
|
fn get_error_class_name(e: &AnyError) -> &'static str {
|
|
deno_runtime::errors::get_error_class_name(e).unwrap_or("Error")
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), AnyError> {
|
|
let module_loader = Rc::new(FsModuleLoader);
|
|
let create_web_worker_cb = Arc::new(|_| {
|
|
todo!("Web workers are not supported in the example");
|
|
});
|
|
let web_worker_event_cb = Arc::new(|_| {
|
|
todo!("Web workers are not supported in the example");
|
|
});
|
|
|
|
let options = WorkerOptions {
|
|
bootstrap: BootstrapOptions {
|
|
args: vec![],
|
|
cpu_count: 1,
|
|
debug_flag: false,
|
|
enable_testing_features: false,
|
|
locale: deno_core::v8::icu::get_language_tag(),
|
|
location: None,
|
|
no_color: false,
|
|
is_tty: false,
|
|
runtime_version: "x".to_string(),
|
|
ts_version: "x".to_string(),
|
|
unstable: false,
|
|
user_agent: "hello_runtime".to_string(),
|
|
inspect: false,
|
|
},
|
|
extensions: vec![],
|
|
extensions_with_js: vec![],
|
|
startup_snapshot: None,
|
|
unsafely_ignore_certificate_errors: None,
|
|
root_cert_store: None,
|
|
seed: None,
|
|
source_map_getter: None,
|
|
format_js_error_fn: None,
|
|
web_worker_preload_module_cb: web_worker_event_cb.clone(),
|
|
web_worker_pre_execute_module_cb: web_worker_event_cb,
|
|
create_web_worker_cb,
|
|
maybe_inspector_server: None,
|
|
should_break_on_first_statement: false,
|
|
should_wait_for_inspector_session: false,
|
|
module_loader,
|
|
npm_resolver: None,
|
|
get_error_class_fn: Some(&get_error_class_name),
|
|
cache_storage_dir: None,
|
|
origin_storage_dir: None,
|
|
blob_store: BlobStore::default(),
|
|
broadcast_channel: InMemoryBroadcastChannel::default(),
|
|
shared_array_buffer_store: None,
|
|
compiled_wasm_module_store: None,
|
|
stdio: Default::default(),
|
|
leak_isolate: true,
|
|
};
|
|
|
|
let js_path =
|
|
Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/hello_runtime.js");
|
|
let main_module = deno_core::resolve_path(&js_path.to_string_lossy())?;
|
|
let permissions = PermissionsContainer::allow_all();
|
|
|
|
let mut worker = MainWorker::bootstrap_from_options(
|
|
main_module.clone(),
|
|
permissions,
|
|
options,
|
|
);
|
|
worker.execute_main_module(&main_module).await?;
|
|
worker.run_event_loop(false).await?;
|
|
Ok(())
|
|
}
|