@@ -75,9 +75,9 @@ static void BM_MakeIdent(benchmark::State& state) {
7575 unsigned short nqubits = state.range (0 );
7676 auto dd = std::make_unique<dd::Package>();
7777 auto line = std::array<short , dd::MAXN>{};
78+ line.fill (-1 );
79+ line[0 ] = 2 ;
7880 for (auto _: state) {
79- line.fill (-1 );
80- line[0 ] = 2 ;
8181 benchmark::DoNotOptimize (dd->makeGateDD (dd::Imat, nqubits, line));
8282 }
8383}
@@ -91,9 +91,9 @@ static void BM_MakeSingleQubitGateDD_TargetTop(benchmark::State& state) {
9191 unsigned short nqubits = state.range (0 );
9292 auto dd = std::make_unique<dd::Package>();
9393 auto line = std::array<short , dd::MAXN>{};
94+ line.fill (-1 );
95+ line[nqubits - 1 ] = 2 ;
9496 for (auto _: state) {
95- line.fill (-1 );
96- line[nqubits - 1 ] = 2 ;
9797 benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
9898 }
9999}
@@ -103,9 +103,9 @@ static void BM_MakeSingleQubitGateDD_TargetMiddle(benchmark::State& state) {
103103 unsigned short nqubits = state.range (0 );
104104 auto dd = std::make_unique<dd::Package>();
105105 auto line = std::array<short , dd::MAXN>{};
106+ line.fill (-1 );
107+ line[nqubits / 2 ] = 2 ;
106108 for (auto _: state) {
107- line.fill (-1 );
108- line[nqubits / 2 ] = 2 ;
109109 benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
110110 }
111111}
@@ -115,9 +115,9 @@ static void BM_MakeSingleQubitGateDD_TargetBottom(benchmark::State& state) {
115115 unsigned short nqubits = state.range (0 );
116116 auto dd = std::make_unique<dd::Package>();
117117 auto line = std::array<short , dd::MAXN>{};
118+ line.fill (-1 );
119+ line[0 ] = 2 ;
118120 for (auto _: state) {
119- line.fill (-1 );
120- line[0 ] = 2 ;
121121 benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
122122 }
123123}
@@ -127,10 +127,10 @@ static void BM_MakeControlledQubitGateDD_ControlBottom_TargetTop(benchmark::Stat
127127 unsigned short nqubits = state.range (0 );
128128 auto dd = std::make_unique<dd::Package>();
129129 auto line = std::array<short , dd::MAXN>{};
130+ line.fill (-1 );
131+ line[0 ] = 1 ;
132+ line[nqubits - 1 ] = 2 ;
130133 for (auto _: state) {
131- line.fill (-1 );
132- line[0 ] = 1 ;
133- line[nqubits - 1 ] = 2 ;
134134 benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
135135 }
136136}
@@ -140,10 +140,10 @@ static void BM_MakeControlledQubitGateDD_ControlBottom_TargetMiddle(benchmark::S
140140 unsigned short nqubits = state.range (0 );
141141 auto dd = std::make_unique<dd::Package>();
142142 auto line = std::array<short , dd::MAXN>{};
143+ line.fill (-1 );
144+ line[0 ] = 1 ;
145+ line[nqubits / 2 ] = 2 ;
143146 for (auto _: state) {
144- line.fill (-1 );
145- line[0 ] = 1 ;
146- line[nqubits / 2 ] = 2 ;
147147 benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
148148 }
149149}
@@ -153,10 +153,10 @@ static void BM_MakeControlledQubitGateDD_ControlTop_TargetMiddle(benchmark::Stat
153153 unsigned short nqubits = state.range (0 );
154154 auto dd = std::make_unique<dd::Package>();
155155 auto line = std::array<short , dd::MAXN>{};
156+ line.fill (-1 );
157+ line[nqubits - 1 ] = 1 ;
158+ line[nqubits / 2 ] = 2 ;
156159 for (auto _: state) {
157- line.fill (-1 );
158- line[nqubits - 1 ] = 1 ;
159- line[nqubits / 2 ] = 2 ;
160160 benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
161161 }
162162}
@@ -166,10 +166,10 @@ static void BM_MakeControlledQubitGateDD_ControlTop_TargetBottom(benchmark::Stat
166166 unsigned short nqubits = state.range (0 );
167167 auto dd = std::make_unique<dd::Package>();
168168 auto line = std::array<short , dd::MAXN>{};
169+ line.fill (-1 );
170+ line[nqubits - 1 ] = 1 ;
171+ line[0 ] = 2 ;
169172 for (auto _: state) {
170- line.fill (-1 );
171- line[nqubits - 1 ] = 1 ;
172- line[0 ] = 2 ;
173173 benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
174174 }
175175}
@@ -179,9 +179,9 @@ static void BM_MakeFullControlledToffoliDD_TargetTop(benchmark::State& state) {
179179 unsigned short nqubits = state.range (0 );
180180 auto dd = std::make_unique<dd::Package>();
181181 auto line = std::array<short , dd::MAXN>{};
182+ line.fill (1 );
183+ line[nqubits - 1 ] = 2 ;
182184 for (auto _: state) {
183- line.fill (1 );
184- line[nqubits - 1 ] = 2 ;
185185 benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
186186 }
187187}
@@ -191,9 +191,9 @@ static void BM_MakeFullControlledToffoliDD_TargetMiddle(benchmark::State& state)
191191 unsigned short nqubits = state.range (0 );
192192 auto dd = std::make_unique<dd::Package>();
193193 auto line = std::array<short , dd::MAXN>{};
194+ line.fill (1 );
195+ line[nqubits / 2 ] = 2 ;
194196 for (auto _: state) {
195- line.fill (1 );
196- line[nqubits / 2 ] = 2 ;
197197 benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
198198 }
199199}
@@ -203,9 +203,9 @@ static void BM_MakeFullControlledToffoliDD_TargetBottom(benchmark::State& state)
203203 unsigned short nqubits = state.range (0 );
204204 auto dd = std::make_unique<dd::Package>();
205205 auto line = std::array<short , dd::MAXN>{};
206+ line.fill (1 );
207+ line[0 ] = 2 ;
206208 for (auto _: state) {
207- line.fill (1 );
208- line[0 ] = 2 ;
209209 benchmark::DoNotOptimize (dd->makeGateDD (dd::Xmat, nqubits, line));
210210 }
211211}
@@ -238,12 +238,12 @@ static void BM_MxV_X(benchmark::State& state) {
238238 unsigned short nqubits = state.range (0 );
239239 auto dd = std::make_unique<dd::Package>();
240240 auto line = std::array<short , dd::MAXN>{};
241+ auto zero = dd->makeZeroState (nqubits);
242+ line.fill (-1 );
243+ line[0 ] = 2 ;
244+ auto x = dd->makeGateDD (dd::Xmat, nqubits, line);
241245
242246 for (auto _: state) {
243- auto zero = dd->makeZeroState (nqubits);
244- line.fill (-1 );
245- line[0 ] = 2 ;
246- auto x = dd->makeGateDD (dd::Xmat, nqubits, line);
247247 auto sim = dd->multiply (x, zero);
248248 benchmark::DoNotOptimize (sim);
249249 // clear compute table so the next iteration does not find the result cached
@@ -256,12 +256,12 @@ static void BM_MxV_H(benchmark::State& state) {
256256 unsigned short nqubits = state.range (0 );
257257 auto dd = std::make_unique<dd::Package>();
258258 auto line = std::array<short , dd::MAXN>{};
259+ auto zero = dd->makeZeroState (nqubits);
260+ line.fill (-1 );
261+ line[0 ] = 2 ;
262+ auto h = dd->makeGateDD (dd::Hmat, nqubits, line);
259263
260264 for (auto _: state) {
261- auto zero = dd->makeZeroState (nqubits);
262- line.fill (-1 );
263- line[0 ] = 2 ;
264- auto h = dd->makeGateDD (dd::Hmat, nqubits, line);
265265 auto sim = dd->multiply (h, zero);
266266 benchmark::DoNotOptimize (sim);
267267 // clear compute table so the next iteration does not find the result cached
@@ -274,12 +274,12 @@ static void BM_MxV_T(benchmark::State& state) {
274274 unsigned short nqubits = state.range (0 );
275275 auto dd = std::make_unique<dd::Package>();
276276 auto line = std::array<short , dd::MAXN>{};
277+ auto zero = dd->makeZeroState (nqubits);
278+ line.fill (-1 );
279+ line[0 ] = 2 ;
280+ auto t = dd->makeGateDD (dd::Tmat, nqubits, line);
277281
278282 for (auto _: state) {
279- auto zero = dd->makeZeroState (nqubits);
280- line.fill (-1 );
281- line[0 ] = 2 ;
282- auto t = dd->makeGateDD (dd::Tmat, nqubits, line);
283283 auto sim = dd->multiply (t, zero);
284284 benchmark::DoNotOptimize (sim);
285285 // clear compute table so the next iteration does not find the result cached
@@ -294,14 +294,14 @@ static void BM_MxV_CX_ControlTop_TargetBottom(benchmark::State& state) {
294294 auto line = std::array<short , dd::MAXN>{};
295295 auto basisStates = std::vector<dd::BasisStates>{nqubits, dd::BasisStates::zero};
296296 basisStates[nqubits - 1 ] = dd::BasisStates::plus;
297+ auto plus = dd->makeBasisState (nqubits, basisStates);
298+ line.fill (-1 );
299+ line[0 ] = 2 ;
300+ line[nqubits - 1 ] = 1 ;
301+ auto cx = dd->makeGateDD (dd::Xmat, nqubits, line);
297302
298303 for (auto _: state) {
299- auto plus = dd->makeBasisState (nqubits, basisStates);
300- line.fill (-1 );
301- line[0 ] = 2 ;
302- line[nqubits - 1 ] = 1 ;
303- auto cx = dd->makeGateDD (dd::Xmat, nqubits, line);
304- auto sim = dd->multiply (cx, plus);
304+ auto sim = dd->multiply (cx, plus);
305305 benchmark::DoNotOptimize (sim);
306306 // clear compute table so the next iteration does not find the result cached
307307 dd->clearComputeTables ();
@@ -315,14 +315,14 @@ static void BM_MxV_CX_ControlBottom_TargetTop(benchmark::State& state) {
315315 auto line = std::array<short , dd::MAXN>{};
316316 auto basisStates = std::vector<dd::BasisStates>{nqubits, dd::BasisStates::zero};
317317 basisStates[0 ] = dd::BasisStates::plus;
318+ auto plus = dd->makeBasisState (nqubits, basisStates);
319+ line.fill (-1 );
320+ line[nqubits - 1 ] = 2 ;
321+ line[0 ] = 1 ;
322+ auto cx = dd->makeGateDD (dd::Xmat, nqubits, line);
318323
319324 for (auto _: state) {
320- auto plus = dd->makeBasisState (nqubits, basisStates);
321- line.fill (-1 );
322- line[nqubits - 1 ] = 2 ;
323- line[0 ] = 1 ;
324- auto cx = dd->makeGateDD (dd::Xmat, nqubits, line);
325- auto sim = dd->multiply (cx, plus);
325+ auto sim = dd->multiply (cx, plus);
326326 benchmark::DoNotOptimize (sim);
327327 // clear compute table so the next iteration does not find the result cached
328328 dd->clearComputeTables ();
@@ -335,8 +335,9 @@ static void BM_MxV_HadamardLayer(benchmark::State& state) {
335335 auto dd = std::make_unique<dd::Package>();
336336 auto line = std::array<short , dd::MAXN>{};
337337
338+ auto zero = dd->makeZeroState (nqubits);
338339 for (auto _: state) {
339- auto sv = dd-> makeZeroState (nqubits) ;
340+ auto sv = zero ;
340341 line.fill (-1 );
341342 for (int i = 0 ; i < nqubits; ++i) {
342343 line[std::max (0 , i - 1 )] = -1 ;
@@ -355,8 +356,9 @@ static void BM_MxV_GHZ(benchmark::State& state) {
355356 auto dd = std::make_unique<dd::Package>();
356357 auto line = std::array<short , dd::MAXN>{};
357358
359+ auto zero = dd->makeZeroState (nqubits);
358360 for (auto _: state) {
359- auto sv = dd-> makeZeroState (nqubits) ;
361+ auto sv = zero ;
360362 line.fill (-1 );
361363 line[nqubits - 1 ] = 2 ;
362364 auto h = dd->makeGateDD (dd::Hmat, nqubits, line);
@@ -378,15 +380,15 @@ static void BM_MxM_Bell(benchmark::State& state) {
378380 unsigned short nqubits = state.range (0 );
379381 auto dd = std::make_unique<dd::Package>();
380382 auto line = std::array<short , dd::MAXN>{};
383+ line.fill (-1 );
384+ line[nqubits - 1 ] = 2 ;
385+ auto h = dd->makeGateDD (dd::Hmat, nqubits, line);
386+ line[nqubits - 1 ] = 1 ;
387+ line[0 ] = 2 ;
388+ auto cx = dd->makeGateDD (dd::Xmat, nqubits, line);
381389
382390 for (auto _: state) {
383- line.fill (-1 );
384- line[nqubits - 1 ] = 2 ;
385- auto h = dd->makeGateDD (dd::Hmat, nqubits, line);
386- line[nqubits - 1 ] = 1 ;
387- line[0 ] = 2 ;
388- auto cx = dd->makeGateDD (dd::Xmat, nqubits, line);
389- auto bell = dd->multiply (cx, h);
391+ auto bell = dd->multiply (cx, h);
390392 benchmark::DoNotOptimize (bell);
391393 // clear compute table so the next iteration does not find the result cached
392394 dd->clearComputeTables ();
0 commit comments