UnitTest: Fix google benchmark

Change-Id: I3ea223c161d49c2f78751c07916398682b70767c
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Marco Bubke
2017-10-24 19:38:47 +02:00
parent a701ca8342
commit 2382824d7b
3 changed files with 19 additions and 16 deletions

View File

@@ -6,18 +6,20 @@ exists($$GOOGLEBENCHMARK_DIR) {
DEFINES += HAVE_STD_REGEX WITH_BENCHMARKS
SOURCES += \
$$GOOGLEBENCHMARK_DIR/src/benchmark.cc \
$$GOOGLEBENCHMARK_DIR/src/benchmark_register.cc \
$$GOOGLEBENCHMARK_DIR/src/colorprint.cc \
$$GOOGLEBENCHMARK_DIR/src/commandlineflags.cc \
$$GOOGLEBENCHMARK_DIR/src/complexity.cc \
$$GOOGLEBENCHMARK_DIR/src/console_reporter.cc \
$$GOOGLEBENCHMARK_DIR/src/counter.cc \
$$GOOGLEBENCHMARK_DIR/src/csv_reporter.cc \
$$GOOGLEBENCHMARK_DIR/src/json_reporter.cc \
$$GOOGLEBENCHMARK_DIR/src/log.cc \
$$GOOGLEBENCHMARK_DIR/src/reporter.cc \
$$GOOGLEBENCHMARK_DIR/src/re_std.cc \
$$GOOGLEBENCHMARK_DIR/src/sleep.cc \
$$GOOGLEBENCHMARK_DIR/src/statistics.cc \
$$GOOGLEBENCHMARK_DIR/src/string_util.cc \
$$GOOGLEBENCHMARK_DIR/src/sysinfo.cc \
$$GOOGLEBENCHMARK_DIR/src/walltime.cc
$$GOOGLEBENCHMARK_DIR/src/timers.cc
win32:LIBS += -lShlwapi
}

View File

@@ -26,6 +26,7 @@
#include <benchmark/benchmark.h>
#include <QByteArray>
#include <QVector>
#include <utils/smallstringvector.h>
@@ -59,46 +60,46 @@ void CreateSmallStringFromLiteral(benchmark::State& state) {
BENCHMARK(CreateSmallStringFromLiteral);
void CreateSmallString(benchmark::State& state) {
auto text = createText(state.range_x());
auto text = createText(state.range(0));
while (state.KeepRunning())
auto string = Utils::SmallString(text.data(), state.range_x());
auto string = Utils::SmallString(text.data(), state.range(0));
}
BENCHMARK(CreateSmallString)->Range(0, 1024);
void CreateQByteArray(benchmark::State& state) {
auto text = createText(state.range_x());
auto text = createText(state.range(0));
while (state.KeepRunning())
QByteArray foo(text.data(), state.range_x());
QByteArray foo(text.data(), state.range(0));
}
BENCHMARK(CreateQByteArray)->Range(0, 1024);
void CreateQString(benchmark::State& state) {
auto text = createText(state.range_x());
auto text = createText(state.range(0));
while (state.KeepRunning())
auto string = QString::fromUtf8(text.data(), state.range_x());
auto string = QString::fromUtf8(text.data(), state.range(0));
}
BENCHMARK(CreateQString)->Range(0, 1024);
void SmallStringAppend(benchmark::State& state) {
auto text = createText(state.range_y());
auto text = createText(state.range(1));
while (state.KeepRunning()) {
auto string = Utils::SmallString();
for (int i = 0; i < state.range_x(); ++i)
for (int i = 0; i < state.range(0); ++i)
string.append(text);
}
}
BENCHMARK(SmallStringAppend)->RangePair(1, 64, 1, 4096);
void QByteArrayAppend(benchmark::State& state) {
auto text = createText(state.range_y());
auto text = createText(state.range(1));
while (state.KeepRunning()) {
auto string = QByteArray();
for (int i = 0; i < state.range_x(); ++i)
for (int i = 0; i < state.range(0); ++i)
string.append(text.data(), text.size());
}
}
@@ -319,8 +320,8 @@ BENCHMARK(Collection_FilterSmallStrings);
void IterateOver(benchmark::State& state) {
Utils::SmallString text = generateRandomSmallString(30);
auto begin = std::next(text.begin(), state.range_x());
auto end = std::next(text.begin(), state.range_y());
auto begin = std::next(text.begin(), state.range(0));
auto end = std::next(text.begin(), state.range(1));
while (state.KeepRunning()) {
std::for_each(begin, end, [] (char x) {

View File

@@ -34,7 +34,7 @@
#include "gtest-qt-printing.h"
#ifdef WITH_BENCHMARKS
#include <benchmark/benchmark_api.h>
#include <benchmark/benchmark.h>
#endif
int main(int argc, char *argv[])