Update code formatting.
This commit is contained in:
parent
ca164dc954
commit
1316ae63d0
@ -1,16 +1,14 @@
|
|||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
|
|
||||||
extern crate test;
|
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
extern crate rand_pcg;
|
extern crate rand_pcg;
|
||||||
|
extern crate test;
|
||||||
|
|
||||||
use test::Bencher;
|
|
||||||
use rand_pcg::Pcg32;
|
|
||||||
use rand::{Rng, SeedableRng};
|
|
||||||
use rand::distributions::Uniform;
|
|
||||||
use rand::seq::SliceRandom;
|
|
||||||
use evalexpr::build_operator_tree;
|
use evalexpr::build_operator_tree;
|
||||||
|
use rand::{distributions::Uniform, seq::SliceRandom, Rng, SeedableRng};
|
||||||
|
use rand_pcg::Pcg32;
|
||||||
use std::hint::black_box;
|
use std::hint::black_box;
|
||||||
|
use test::Bencher;
|
||||||
|
|
||||||
const BENCHMARK_LEN: usize = 100_000;
|
const BENCHMARK_LEN: usize = 100_000;
|
||||||
const EXPONENTIAL_TUPLE_ITERATIONS: usize = 12;
|
const EXPONENTIAL_TUPLE_ITERATIONS: usize = 12;
|
||||||
@ -69,9 +67,7 @@ fn bench_parse_long_expression_chains(bencher: &mut Bencher) {
|
|||||||
let mut gen = Pcg32::seed_from_u64(0);
|
let mut gen = Pcg32::seed_from_u64(0);
|
||||||
let long_expression_chain = generate_expression_chain(BENCHMARK_LEN, &mut gen);
|
let long_expression_chain = generate_expression_chain(BENCHMARK_LEN, &mut gen);
|
||||||
|
|
||||||
bencher.iter(|| {
|
bencher.iter(|| build_operator_tree(&long_expression_chain).unwrap());
|
||||||
build_operator_tree(&long_expression_chain).unwrap()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
@ -79,9 +75,7 @@ fn bench_parse_deep_expression_trees(bencher: &mut Bencher) {
|
|||||||
let mut gen = Pcg32::seed_from_u64(15);
|
let mut gen = Pcg32::seed_from_u64(15);
|
||||||
let deep_expression_tree = generate_expression(BENCHMARK_LEN, &mut gen);
|
let deep_expression_tree = generate_expression(BENCHMARK_LEN, &mut gen);
|
||||||
|
|
||||||
bencher.iter(|| {
|
bencher.iter(|| build_operator_tree(&deep_expression_tree).unwrap());
|
||||||
build_operator_tree(&deep_expression_tree).unwrap()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
@ -99,27 +93,28 @@ fn bench_parse_many_small_expressions(bencher: &mut Bencher) {
|
|||||||
#[bench]
|
#[bench]
|
||||||
fn bench_evaluate_long_expression_chains(bencher: &mut Bencher) {
|
fn bench_evaluate_long_expression_chains(bencher: &mut Bencher) {
|
||||||
let mut gen = Pcg32::seed_from_u64(0);
|
let mut gen = Pcg32::seed_from_u64(0);
|
||||||
let long_expression_chain = build_operator_tree(&generate_expression_chain(BENCHMARK_LEN, &mut gen)).unwrap();
|
let long_expression_chain =
|
||||||
|
build_operator_tree(&generate_expression_chain(BENCHMARK_LEN, &mut gen)).unwrap();
|
||||||
|
|
||||||
bencher.iter(|| {
|
bencher.iter(|| long_expression_chain.eval().unwrap());
|
||||||
long_expression_chain.eval().unwrap()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_evaluate_deep_expression_trees(bencher: &mut Bencher) {
|
fn bench_evaluate_deep_expression_trees(bencher: &mut Bencher) {
|
||||||
let mut gen = Pcg32::seed_from_u64(15);
|
let mut gen = Pcg32::seed_from_u64(15);
|
||||||
let deep_expression_tree = build_operator_tree(&generate_expression(BENCHMARK_LEN, &mut gen)).unwrap();
|
let deep_expression_tree =
|
||||||
|
build_operator_tree(&generate_expression(BENCHMARK_LEN, &mut gen)).unwrap();
|
||||||
|
|
||||||
bencher.iter(|| {
|
bencher.iter(|| deep_expression_tree.eval().unwrap());
|
||||||
deep_expression_tree.eval().unwrap()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_evaluate_many_small_expressions(bencher: &mut Bencher) {
|
fn bench_evaluate_many_small_expressions(bencher: &mut Bencher) {
|
||||||
let mut gen = Pcg32::seed_from_u64(33);
|
let mut gen = Pcg32::seed_from_u64(33);
|
||||||
let small_expressions: Vec<_> = generate_small_expressions(BENCHMARK_LEN, &mut gen).iter().map(|expression| build_operator_tree(&expression).unwrap()).collect();
|
let small_expressions: Vec<_> = generate_small_expressions(BENCHMARK_LEN, &mut gen)
|
||||||
|
.iter()
|
||||||
|
.map(|expression| build_operator_tree(&expression).unwrap())
|
||||||
|
.collect();
|
||||||
|
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
for expression in &small_expressions {
|
for expression in &small_expressions {
|
||||||
@ -131,10 +126,12 @@ fn bench_evaluate_many_small_expressions(bencher: &mut Bencher) {
|
|||||||
#[bench]
|
#[bench]
|
||||||
fn bench_evaluate_large_tuple_expression(bencher: &mut Bencher) {
|
fn bench_evaluate_large_tuple_expression(bencher: &mut Bencher) {
|
||||||
let mut gen = Pcg32::seed_from_u64(44);
|
let mut gen = Pcg32::seed_from_u64(44);
|
||||||
let large_tuple_expression = build_operator_tree(&generate_large_tuple_expression(EXPONENTIAL_TUPLE_ITERATIONS, &mut gen)).unwrap();
|
let large_tuple_expression = build_operator_tree(&generate_large_tuple_expression(
|
||||||
|
EXPONENTIAL_TUPLE_ITERATIONS,
|
||||||
|
&mut gen,
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
dbg!(&large_tuple_expression);
|
dbg!(&large_tuple_expression);
|
||||||
|
|
||||||
bencher.iter(|| {
|
bencher.iter(|| large_tuple_expression.eval().unwrap());
|
||||||
large_tuple_expression.eval().unwrap()
|
|
||||||
});
|
|
||||||
}
|
}
|
@ -2,5 +2,5 @@ edition = "2018"
|
|||||||
reorder_imports=true
|
reorder_imports=true
|
||||||
reorder_modules=true
|
reorder_modules=true
|
||||||
format_strings=true
|
format_strings=true
|
||||||
merge_imports=true
|
imports_granularity="Crate"
|
||||||
match_block_trailing_comma=true
|
match_block_trailing_comma=true
|
@ -1,4 +1,8 @@
|
|||||||
use crate::{token::Token, value::{TupleType, EMPTY_VALUE}, EmptyType, FloatType, IntType, HashMapContext};
|
use crate::{
|
||||||
|
token::Token,
|
||||||
|
value::{TupleType, EMPTY_VALUE},
|
||||||
|
EmptyType, FloatType, HashMapContext, IntType,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
context::Context,
|
context::Context,
|
||||||
|
@ -452,7 +452,6 @@ fn test_shortcut_functions() {
|
|||||||
.eval_string_with_context_mut(&mut context),
|
.eval_string_with_context_mut(&mut context),
|
||||||
Ok("a string".to_string())
|
Ok("a string".to_string())
|
||||||
);
|
);
|
||||||
;
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
build_operator_tree("3.3")
|
build_operator_tree("3.3")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
Loading…
Reference in New Issue
Block a user