-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2277 from bishopcheckmate/perf/fast-fail-group-fr…
…om-x-coord perf: optimize console's group from_x_coordinate
- Loading branch information
Showing
10 changed files
with
168 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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 criterion::Criterion; | ||
use snarkvm_console_network::{environment::prelude::*, Testnet3}; | ||
use snarkvm_console_types::{Field, Group}; | ||
|
||
type CurrentNetwork = Testnet3; | ||
|
||
fn group_from_field(c: &mut Criterion) { | ||
let rng = &mut TestRng::default(); | ||
|
||
c.bench_function("group_from_field", move |b| { | ||
let fields: Vec<Field<CurrentNetwork>> = (0..1000).map(|_| rng.gen()).collect(); | ||
|
||
b.iter(|| { | ||
for field in &fields { | ||
let group = Group::from_field(field); | ||
let _ = std::hint::black_box(group); | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
fn group_from_field_on_curve(c: &mut Criterion) { | ||
let rng = &mut TestRng::default(); | ||
|
||
c.bench_function("group_from_field_on_curve", move |b| { | ||
type Projective = <CurrentNetwork as Environment>::Projective; | ||
|
||
let fields: Vec<Field<CurrentNetwork>> = | ||
(0..1000).map(|_| rng.gen::<Projective>().to_affine().to_x_coordinate()).map(Field::new).collect(); | ||
|
||
b.iter(|| { | ||
for field in &fields { | ||
let group = Group::from_field(field); | ||
let _ = std::hint::black_box(group); | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
fn group_from_field_off_curve(c: &mut Criterion) { | ||
let rng = &mut TestRng::default(); | ||
|
||
c.bench_function("group_from_field_off_curve", move |b| { | ||
type Affine = <CurrentNetwork as Environment>::Affine; | ||
|
||
let fields: Vec<_> = std::iter::repeat(()) | ||
.map(|_| rng.gen::<Field<CurrentNetwork>>()) | ||
.filter(|&field| Affine::from_x_coordinate(*field, true).is_none()) | ||
.take(1000) | ||
.collect(); | ||
|
||
b.iter(|| { | ||
for field in &fields { | ||
let group = Group::from_field(field); | ||
let _ = std::hint::black_box(group); | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group! { | ||
name = group; | ||
config = Criterion::default().sample_size(20); | ||
targets = group_from_field, group_from_field_on_curve, group_from_field_off_curve | ||
} | ||
|
||
criterion_main!(group); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters