Skip to content

Commit 034e0f8

Browse files
authored
Add benchmark to new parser (#2288)
1 parent 51d5245 commit 034e0f8

File tree

5 files changed

+3183
-0
lines changed

5 files changed

+3183
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/qsc_qasm3/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ rustc-hash = { workspace = true }
2424
thiserror = { workspace = true }
2525

2626
[dev-dependencies]
27+
criterion = { workspace = true, features = ["cargo_bench_support"] }
2728
difference = { workspace = true }
2829
expect-test = { workspace = true }
2930
indoc = { workspace = true }
@@ -38,3 +39,10 @@ fs = []
3839

3940
[lints]
4041
workspace = true
42+
43+
[lib]
44+
bench = false
45+
46+
[[bench]]
47+
name = "rgqft_multiplier"
48+
harness = false
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
5+
use qsc_qasm3::{
6+
compile_to_qsharp_ast_with_config, io::InMemorySourceResolver, CompilerConfig, OutputSemantics,
7+
ProgramType, QasmCompileUnit, QubitSemantics,
8+
};
9+
10+
fn rgqft_multiplier(source: &str) -> QasmCompileUnit {
11+
let config = CompilerConfig::new(
12+
QubitSemantics::Qiskit,
13+
OutputSemantics::OpenQasm,
14+
ProgramType::File,
15+
Some("Test".into()),
16+
None,
17+
);
18+
compile_to_qsharp_ast_with_config(source, "", None::<&mut InMemorySourceResolver>, config)
19+
}
20+
21+
pub fn rgqft_multiplier_1q(c: &mut Criterion) {
22+
const SOURCE: &str = include_str!("./rgqft_multiplier_1q.qasm");
23+
24+
c.bench_function("rgqft_multiplier_1q sample compilation", |b| {
25+
b.iter(move || black_box(rgqft_multiplier(SOURCE)));
26+
});
27+
}
28+
29+
pub fn rgqft_multiplier_4q(c: &mut Criterion) {
30+
const SOURCE: &str = include_str!("./rgqft_multiplier_4q.qasm");
31+
32+
c.bench_function("rgqft_multiplier_4q sample compilation", |b| {
33+
b.iter(move || black_box(rgqft_multiplier(SOURCE)));
34+
});
35+
}
36+
37+
criterion_group!(benches, rgqft_multiplier_1q, rgqft_multiplier_4q);
38+
criterion_main!(benches);
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
OPENQASM 3.0;
5+
include "stdgates.inc";
6+
qubit[1] a;
7+
qubit[1] b;
8+
qubit[2] out;
9+
h out[1];
10+
rz(pi/4) out[1];
11+
cx out[1], out[0];
12+
rz(-pi/4) out[0];
13+
cx out[1], out[0];
14+
rz(pi/4) out[0];
15+
h out[0];
16+
cx a[0], out[0];
17+
rz(-pi/8) out[0];
18+
rx(pi/2) out[0];
19+
rz(pi) out[0];
20+
rx(pi/2) out[0];
21+
rz(9.032078879070655) out[0];
22+
cx b[0], out[0];
23+
rz(-7*pi/8) out[0];
24+
rx(pi/2) out[0];
25+
rz(pi) out[0];
26+
rx(pi/2) out[0];
27+
rz(6.675884388878311) out[0];
28+
cx a[0], out[0];
29+
rz(-pi/8) out[0];
30+
rx(pi/2) out[0];
31+
rz(pi) out[0];
32+
rx(pi/2) out[0];
33+
rz(9.032078879070655) out[0];
34+
cx b[0], out[0];
35+
rz(pi/4) b[0];
36+
rx(pi/2) b[0];
37+
rz(pi) b[0];
38+
rx(pi/2) b[0];
39+
rz(3*pi) b[0];
40+
cx a[0], b[0];
41+
rz(-pi/4) b[0];
42+
rx(pi/2) b[0];
43+
rz(pi) b[0];
44+
rx(pi/2) b[0];
45+
rz(3*pi) b[0];
46+
cx a[0], b[0];
47+
rz(pi/4) a[0];
48+
cx a[0], out[1];
49+
rz(-7*pi/8) out[0];
50+
rx(pi/2) out[0];
51+
rz(pi) out[0];
52+
rx(pi/2) out[0];
53+
rz(6.675884388878311) out[0];
54+
h out[0];
55+
rz(-pi/16) out[1];
56+
rx(pi/2) out[1];
57+
rz(pi) out[1];
58+
rx(pi/2) out[1];
59+
rz(9.228428419920018) out[1];
60+
cx b[0], out[1];
61+
rz(-15*pi/16) out[1];
62+
rx(pi/2) out[1];
63+
rz(pi) out[1];
64+
rx(pi/2) out[1];
65+
rz(6.4795348480289485) out[1];
66+
cx a[0], out[1];
67+
rz(-pi/16) out[1];
68+
rx(pi/2) out[1];
69+
rz(pi) out[1];
70+
rx(pi/2) out[1];
71+
rz(9.228428419920018) out[1];
72+
cx b[0], out[1];
73+
rz(pi/8) b[0];
74+
rx(pi/2) b[0];
75+
rz(pi) b[0];
76+
rx(pi/2) b[0];
77+
rz(3*pi) b[0];
78+
cx a[0], b[0];
79+
rz(-pi/8) b[0];
80+
rx(pi/2) b[0];
81+
rz(pi) b[0];
82+
rx(pi/2) b[0];
83+
rz(3*pi) b[0];
84+
cx a[0], b[0];
85+
rz(pi/8) a[0];
86+
rz(-15*pi/16) out[1];
87+
rx(pi/2) out[1];
88+
rz(pi) out[1];
89+
rx(pi/2) out[1];
90+
rz(6.4795348480289485) out[1];
91+
rz(-pi/4) out[1];
92+
cx out[1], out[0];
93+
rz(pi/4) out[0];
94+
cx out[1], out[0];
95+
rz(-pi/4) out[0];
96+
h out[1];

0 commit comments

Comments
 (0)