1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
// Copyright 2017 Global Phasing Ltd.
// Microbenchmark of functions from symmetry.hpp
// Requires the google/benchmark library. It can be built manually:
// c++ -Wall -O2 -I../include -I$GB/include sym.cpp $GB/src/libbenchmark.a -pthread
#include <benchmark/benchmark.h>
#include <gemmi/symmetry.hpp>
constexpr const char* TRIPLETS[10] = {
"x,y,z", "-x,-y+1/2,z", "x+1/4,y+1/4,z", "x+1/4,y+1/4,-x+z-1/4",
"1/2+X,1/2-Y,1/2+Z", "-Z,-X,Y", "Y+1/2,X+1/2,Z+1/2",
"2/3+X,1/3+X-Y,5/6+Z", "-x+1/2,-y+1/2,z", " -x,-y, -z" };
constexpr const char* HALL_SYMBOLS[] = {
"p 1", "C 2y", "I 2y", "C 2y (x,y,-x+z)",
"P 2ac 2ab", "F 4d 2 3 -1cd", "-F 4ud 2vw 3 (x-1/8,y-1/8,z-1/8)"
};
static void bm_parse_triplet_all(benchmark::State& state) {
for (auto _ : state)
for (const char* triplet : TRIPLETS)
benchmark::DoNotOptimize(gemmi::parse_triplet(triplet));
}
/*static*/ void bm_make_triplet(benchmark::State& state) {
int n = state.range(0);
gemmi::Op op = gemmi::parse_triplet(TRIPLETS[n]);
for (auto _ : state)
benchmark::DoNotOptimize(op.triplet());
}
static void bm_make_triplet_all(benchmark::State& state) {
gemmi::Op ops[10];
for (int i = 0; i != 10; ++i)
ops[i] = gemmi::parse_triplet(TRIPLETS[i]);
for (auto _ : state)
for (const gemmi::Op& op : ops)
benchmark::DoNotOptimize(op.triplet());
}
static void bm_generators_from_hall(benchmark::State& state) {
int n = state.range(0);
const char* hall = HALL_SYMBOLS[n];
for (auto _ : state)
benchmark::DoNotOptimize(gemmi::generators_from_hall(hall));
}
static void bm_add_elements(benchmark::State& state) {
int n = state.range(0);
const char* hall = HALL_SYMBOLS[n];
gemmi::GroupOps gops = gemmi::generators_from_hall(hall);
for (auto _ : state) {
gemmi::GroupOps copy = gops;
copy.add_missing_elements();
benchmark::DoNotOptimize(copy);
}
}
BENCHMARK(bm_parse_triplet_all);
//BENCHMARK(bm_make_triplet)->DenseRange(0, 9);
BENCHMARK(bm_make_triplet_all);
BENCHMARK(bm_generators_from_hall)->DenseRange(0, 6);
BENCHMARK(bm_add_elements)->DenseRange(0, 6);
BENCHMARK_MAIN();
// gemmi::parse_triplet(): 50-300 ns/triplet
// gemmi::make_triplet(): 40-120 ns/triplet
// gemmi::generators_from_hall(): 60-1000 ns
// GroupOps::add_missing_elements(): for P212121: ~500 ns
// for Fm-3m: 2700ns w/ Dimino, 28000 ns w/o
|