diff --git a/Cargo.lock b/Cargo.lock index 3697583dfc..141d87dd3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2759,6 +2759,7 @@ dependencies = [ name = "snarkvm-circuit-types-field" version = "0.16.19" dependencies = [ + "criterion", "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", "snarkvm-console-types-field", diff --git a/circuit/types/field/Cargo.toml b/circuit/types/field/Cargo.toml index acc1367886..918186a710 100644 --- a/circuit/types/field/Cargo.toml +++ b/circuit/types/field/Cargo.toml @@ -6,6 +6,11 @@ description = "Field circuit for a decentralized virtual machine" license = "Apache-2.0" edition = "2021" +[[bench]] +name = "mul" +path = "benches/mul.rs" +harness = false + [dependencies.console] package = "snarkvm-console-types-field" path = "../../../console/types/field" @@ -20,6 +25,9 @@ version = "=0.16.19" path = "../boolean" version = "=0.16.19" +[dev-dependencies.criterion] +version = "0.5" + [features] default = [ "enable_console" ] enable_console = [ "console" ] diff --git a/circuit/types/field/benches/mul.rs b/circuit/types/field/benches/mul.rs new file mode 100644 index 0000000000..ba93c66267 --- /dev/null +++ b/circuit/types/field/benches/mul.rs @@ -0,0 +1,41 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[macro_use] +extern crate criterion; + +use snarkvm_circuit_environment::*; +use snarkvm_circuit_types_field::Field; + +use criterion::Criterion; + +fn bench_mul(c: &mut Criterion) { + c.bench_function("Field::mul_assign", move |b| { + let one = Field::::one(); + let two = one.clone() + &one; + let mut base = two.clone(); + + b.iter(|| { + base *= &two; + }) + }); +} + +criterion_group! { + name = mul; + config = Criterion::default(); + targets = bench_mul +} + +criterion_main!(mul);