From 7cccf2afe7d4b992f7286786301edf845f70fe0b Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Mon, 8 Jan 2024 11:38:51 +0300 Subject: [PATCH] Add benchmarking on proof generation --- membership-proof/wasm-nova/Cargo.toml | 1 + membership-proof/wasm-nova/tests/lib.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/membership-proof/wasm-nova/Cargo.toml b/membership-proof/wasm-nova/Cargo.toml index 699314a..c0c1ca8 100644 --- a/membership-proof/wasm-nova/Cargo.toml +++ b/membership-proof/wasm-nova/Cargo.toml @@ -34,3 +34,4 @@ crate-type = ["cdylib", "rlib"] [dev-dependencies] wasm-bindgen-test = "0.3.37" +web-sys = { version = "0.3", features = ["Performance"] } \ No newline at end of file diff --git a/membership-proof/wasm-nova/tests/lib.rs b/membership-proof/wasm-nova/tests/lib.rs index 796569f..d51572e 100644 --- a/membership-proof/wasm-nova/tests/lib.rs +++ b/membership-proof/wasm-nova/tests/lib.rs @@ -3,6 +3,8 @@ use wasm_bindgen_test::*; use wasm_nova::wasm::{ generate_params, generate_proof, read_filem }; +use web_sys::window; // Import the window function + #[wasm_bindgen_test] async fn ftest() { @@ -16,6 +18,15 @@ async fn gtest() { let pp = generate_params("output/proofOfInnocence.cbor", "http://127.0.0.1:8000").await; let input_json_str = read_filem("output/inputs.json", "http://127.0.0.1:8000").await; let start_json_str = read_filem("output/start.json", "http://127.0.0.1:8000").await; + // Start timing + let performance = window().expect("should have a Window").performance().expect("should have a Performance"); + let start_time = performance.now(); + generate_proof(pp, "output/proofOfInnocence.r1cs", "output/proofOfInnocence_js/proofOfInnocence.wasm", &input_json_str, &start_json_str, "http://127.0.0.1:8000").await; -} + // End timing + let end_time = performance.now(); + let elapsed_time = end_time - start_time; + console_log!("Elapsed time: {} milliseconds", elapsed_time); + +} \ No newline at end of file