microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
compiler/qsc/benches/large.rs
57lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | allocator::assign_global!(); |
| 5 | |
| 6 | use criterion::{criterion_group, criterion_main, Criterion}; |
| 7 | use qsc::{ |
| 8 | compile::{self, compile}, |
| 9 | TargetCapabilityFlags, |
| 10 | }; |
| 11 | use qsc_data_structures::language_features::LanguageFeatures; |
| 12 | use qsc_frontend::compile::{PackageStore, SourceMap}; |
| 13 | use qsc_passes::PackageType; |
| 14 | |
| 15 | const INPUT: &str = include_str!("./large.qs"); |
| 16 | |
| 17 | pub fn large_file(c: &mut Criterion) { |
| 18 | c.bench_function("Large input file compilation", |b| { |
| 19 | let mut store = PackageStore::new(compile::core()); |
| 20 | let std = store.insert(compile::std(&store, TargetCapabilityFlags::all())); |
| 21 | b.iter(|| { |
| 22 | let sources = SourceMap::new([("large.qs".into(), INPUT.into())], None); |
| 23 | let (_, reports) = compile( |
| 24 | &store, |
| 25 | &[(std, None)], |
| 26 | sources, |
| 27 | PackageType::Exe, |
| 28 | TargetCapabilityFlags::all(), |
| 29 | LanguageFeatures::default(), |
| 30 | ); |
| 31 | assert!(reports.is_empty()); |
| 32 | }); |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | pub fn large_file_interpreter(c: &mut Criterion) { |
| 37 | c.bench_function("Large input file compilation (interpreter)", |b| { |
| 38 | b.iter(|| { |
| 39 | let sources = SourceMap::new([("large.qs".into(), INPUT.into())], None); |
| 40 | let (std_id, store) = |
| 41 | qsc::compile::package_store_with_stdlib(TargetCapabilityFlags::all()); |
| 42 | |
| 43 | let _evaluator = qsc::interpret::Interpreter::new( |
| 44 | sources, |
| 45 | PackageType::Exe, |
| 46 | TargetCapabilityFlags::all(), |
| 47 | LanguageFeatures::default(), |
| 48 | store, |
| 49 | &[(std_id, None)], |
| 50 | ) |
| 51 | .expect("code should compile"); |
| 52 | }); |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | criterion_group!(benches, large_file, large_file_interpreter); |
| 57 | criterion_main!(benches); |