-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from Krzmbrzl/benchmarks
More benchmarks
- Loading branch information
Showing
7 changed files
with
179 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
#include <SeQuant/core/expr.hpp> | ||
#include <SeQuant/core/expr_algorithm.hpp> | ||
#include <SeQuant/core/parse.hpp> | ||
|
||
using namespace sequant; | ||
|
||
static constexpr std::size_t nInputs = 6; | ||
|
||
static ExprPtr get_expression(std::size_t i) { | ||
switch (i) { | ||
case 1: | ||
return parse_expr(L"g{a1,i5;i6,p12}:A"); | ||
case 2: | ||
return parse_expr(L"g{a1,i5;i6,p12}:A t{i6,i7;a1,a2}:A"); | ||
case 3: | ||
return parse_expr( | ||
L"A{i1,i2;a1,a2}:A g{i3,i4;a3,a4}:A t{a1,a3;i3,i4}:A " | ||
L"t{a2,a4;i1,i2}:A"); | ||
case 4: | ||
return parse_expr( | ||
L"A{i1,i2;a1,a2}:A DF{i3;a3;p1} DF{i4;a4;p1} t{a1;i3} t{a3;i4} " | ||
L"t{a2;i1} t{a4;i2}"); | ||
case 5: | ||
return parse_expr(L"g{i3,i4;a3<i1,i4>,a4<i2>} s{a1<i1,i2>;a5<i3>}"); | ||
case 6: | ||
return parse_expr( | ||
L"s{a2<i1,i2>;a6<i2,i4>} g{i3,i4;a3<i2,i4>,a4<i1,i3>} " | ||
L"t{a3<i2,i4>,a6<i2,i4>;i4,i2}"); | ||
} | ||
|
||
throw "Invalid index"; | ||
} | ||
|
||
static void canonicalize(benchmark::State &state) { | ||
ExprPtr input = get_expression(state.range(0)); | ||
|
||
for (auto _ : state) { | ||
ExprPtr canonicalized = canonicalize(input->clone()); | ||
|
||
// Prevent canonicalization from being optimized away by the compiler | ||
benchmark::DoNotOptimize(canonicalized); | ||
} | ||
} | ||
|
||
BENCHMARK(canonicalize)->DenseRange(1, nInputs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
#include <SeQuant/core/expr.hpp> | ||
#include <SeQuant/core/expr_algorithm.hpp> | ||
#include <SeQuant/core/parse.hpp> | ||
|
||
using namespace sequant; | ||
|
||
static constexpr std::size_t nInputs = 2; | ||
|
||
static ExprPtr get_expression(std::size_t i) { | ||
switch (i) { | ||
case 1: | ||
return parse_expr( | ||
L"1/2 A{i1,i2;a1,a2}:A g{i3,i4;a3,a4}:A t{a1,a3;i3,i4}:A " | ||
L"t{a2,a4;i1,i2}:A" | ||
L"- 1/2 A{i2,i1;a1,a2}:A g{i3,i4;a4,a3}:A t{a2,a3;i2,i1}:A " | ||
L"t{a4,a1;i3,i4}:A "); | ||
case 2: | ||
return parse_expr( | ||
L"A{p4;p1;}:A 1/3 g{p1,p2;p3,p4}:A t{p3;p2} " | ||
L"+ A{p1;p4;}:A 1/3 g{p4,p2;p3,p1}:A t{p3;p2} " | ||
L"+ A{p3;p1;}:A 1/3 g{p2,p1;p3,p4}:A t{p4;p2} "); | ||
} | ||
|
||
throw "Invalid index"; | ||
} | ||
|
||
template <bool rapid_only> | ||
static void simplify(benchmark::State &state) { | ||
ExprPtr input = get_expression(state.range(0)); | ||
|
||
for (auto _ : state) { | ||
ExprPtr expression = input->clone(); | ||
if constexpr (rapid_only) { | ||
rapid_simplify(expression); | ||
} else { | ||
simplify(expression); | ||
} | ||
|
||
// Prevent simplification from being optimized away by the compiler | ||
benchmark::DoNotOptimize(expression); | ||
} | ||
} | ||
|
||
BENCHMARK(simplify<false>)->Name("simplify")->DenseRange(1, nInputs); | ||
|
||
BENCHMARK(simplify<true>)->Name("rapid_simplify")->DenseRange(1, nInputs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
#include <SeQuant/core/expr.hpp> | ||
#include <SeQuant/core/expr_algorithm.hpp> | ||
#include <SeQuant/core/parse.hpp> | ||
#include <SeQuant/domain/mbpt/spin.hpp> | ||
|
||
using namespace sequant; | ||
|
||
static constexpr std::size_t nInputs = 2; | ||
|
||
static ExprPtr get_expression(std::size_t i) { | ||
switch (i) { | ||
case 1: | ||
return parse_expr(L"2 t{i1;a1<i1>} F{a1<i1>;i1}"); | ||
case 2: | ||
return parse_expr( | ||
L"f{i1;a1} t{a1;i1} + 1/2 g{i1,i2;a1,a2}:A t{a1;i1} t{a2;i2} " | ||
L"+ 1/4 g{i1,i2;a1,a2}:A t{a1,a2;i1,i2}:A"); | ||
} | ||
|
||
throw "Invalid index"; | ||
} | ||
|
||
template <bool closed_shell> | ||
static void spintrace(benchmark::State &state, bool assume_spinfree) { | ||
ExprPtr input = get_expression(state.range(0)); | ||
|
||
for (auto _ : state) { | ||
ExprPtr result = [&]() { | ||
if constexpr (closed_shell) { | ||
return closed_shell_spintrace(input->clone()); | ||
} else { | ||
return spintrace(input->clone(), {}, assume_spinfree); | ||
} | ||
}(); | ||
|
||
// Prevent spintracing from being optimized away by the compiler | ||
benchmark::DoNotOptimize(result); | ||
} | ||
} | ||
|
||
BENCHMARK_CAPTURE(spintrace<false>, spintrace_remove_spin, true) | ||
->DenseRange(1, nInputs); | ||
|
||
BENCHMARK_CAPTURE(spintrace<false>, spintrace_keep_spin, false) | ||
->DenseRange(1, nInputs); | ||
|
||
BENCHMARK_CAPTURE(spintrace<true>, closed_shell_spintrace, true) | ||
->DenseRange(1, nInputs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters