Add benchmarks for switch statement.
This commit is contained in:
parent
bc07b4fa84
commit
b0c66eb5e5
@ -156,3 +156,57 @@ fn bench_eval_loop_strings_no_build(bench: &mut Bencher) {
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_eval_switch(bench: &mut Bencher) {
|
||||
let script = r#"
|
||||
let sum = 0;
|
||||
|
||||
for x in range(0, 10000) {
|
||||
sum += switch x % 5 {
|
||||
0 => 10,
|
||||
1 => 12,
|
||||
2 => 42,
|
||||
3 => 1,
|
||||
_ => 9
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
let mut engine = Engine::new();
|
||||
engine.set_optimization_level(OptimizationLevel::None);
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_eval_nested_if(bench: &mut Bencher) {
|
||||
let script = r#"
|
||||
let sum = 0;
|
||||
|
||||
for x in range(0, 10000) {
|
||||
let rem = x % 5;
|
||||
|
||||
sum += if rem == 0 {
|
||||
10
|
||||
} else if rem == 1 {
|
||||
12
|
||||
} else if rem == 2 {
|
||||
42
|
||||
} else if rem == 3 {
|
||||
1
|
||||
} else{
|
||||
9
|
||||
};
|
||||
}
|
||||
"#;
|
||||
|
||||
let mut engine = Engine::new();
|
||||
engine.set_optimization_level(OptimizationLevel::None);
|
||||
|
||||
let ast = engine.compile(script).unwrap();
|
||||
|
||||
bench.iter(|| engine.consume_ast(&ast).unwrap());
|
||||
}
|
||||
|
@ -2590,7 +2590,7 @@ fn parse_fn(
|
||||
(Token::RightParen, _) => break,
|
||||
(Token::Identifier(s), pos) => {
|
||||
if params.iter().any(|(p, _)| p == &s) {
|
||||
return Err(PERR::FnDuplicatedParam(name.to_string(), s).into_err(pos));
|
||||
return Err(PERR::FnDuplicatedParam(name, s).into_err(pos));
|
||||
}
|
||||
let s = state.get_interned_string(s);
|
||||
state.stack.push((s.clone(), ScopeEntryType::Normal));
|
||||
|
Loading…
Reference in New Issue
Block a user