diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-11-19 15:54:28 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-11-20 10:16:59 +0000 |
commit | 1776164d76a34d81e887924c372be4c5b3cddc2a (patch) | |
tree | 2bc98d5fb22653eb259b4656f5215ecd8cdd2a81 /searchlib/src | |
parent | d328b6ce8389fb12c76d813476fff925c452c1cb (diff) |
Address comment by specifying timeunit in the type.
Diffstat (limited to 'searchlib/src')
10 files changed, 11 insertions, 227 deletions
diff --git a/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp b/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp index b976f76c3fb..10d63090464 100644 --- a/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp +++ b/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp @@ -167,14 +167,14 @@ LoadAttribute::Main() AttributePtr ptr = AttributeFactory::createAttribute(fileName, c); fastos::StopWatch timer; load(ptr); - std::cout << "load time: " << timer.stop().elapsed().ms() << " seconds " << std::endl; + std::cout << "load time: " << timer.elapsed().ms() << " seconds " << std::endl; std::cout << "numDocs: " << ptr->getNumDocs() << std::endl; if (doApplyUpdate) { timer.restart(); applyUpdate(ptr); - std::cout << "update time: " << timer.stop().elapsed().ms() << " seconds " << std::endl; + std::cout << "update time: " << timer.elapsed().ms() << " seconds " << std::endl; } if (doPrintContent) { @@ -193,7 +193,7 @@ LoadAttribute::Main() std::cout << "saving attribute: " << saveFile << std::endl; timer.restart(); ptr->save(saveFile); - std::cout << "save time: " << timer.stop().elapsed().ms() << " seconds " << std::endl; + std::cout << "save time: " << timer.elapsed().ms() << " seconds " << std::endl; } return 0; diff --git a/searchlib/src/tests/util/bufferwriter/CMakeLists.txt b/searchlib/src/tests/util/bufferwriter/CMakeLists.txt index 511c7b566cf..406dddb9a05 100644 --- a/searchlib/src/tests/util/bufferwriter/CMakeLists.txt +++ b/searchlib/src/tests/util/bufferwriter/CMakeLists.txt @@ -6,11 +6,3 @@ vespa_add_executable(searchlib_bufferwriter_test_app TEST searchlib ) vespa_add_test(NAME searchlib_bufferwriter_test_app COMMAND searchlib_bufferwriter_test_app) -vespa_add_executable(searchlib_bufferwriter_bm_app - SOURCES - work.cpp - bm.cpp - DEPENDS - searchlib -) -vespa_add_test(NAME searchlib_bufferwriter_bm_app COMMAND searchlib_bufferwriter_bm_app BENCHMARK) diff --git a/searchlib/src/tests/util/bufferwriter/bm.cpp b/searchlib/src/tests/util/bufferwriter/bm.cpp deleted file mode 100644 index ac3cc3a09b1..00000000000 --- a/searchlib/src/tests/util/bufferwriter/bm.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "work.h" -#include <vespa/searchlib/util/drainingbufferwriter.h> -#include <vespa/vespalib/testkit/testapp.h> -#include <vespa/fastos/timestamp.h> -#include <iostream> - -#include <vespa/log/log.h> -LOG_SETUP("bufferwriter_bm"); - -using search::DrainingBufferWriter; - -constexpr size_t million = 1000000; - -enum class WorkFuncDispatch -{ - DIRECT, - LAMBDA, - FUNCTOR, - FUNCTOR2 -}; - - -template <typename T> -void -callWork(size_t size, WorkFuncDispatch dispatch) -{ - std::vector<T> foo; - DrainingBufferWriter writer; - foo.resize(size); - std::cout << "will write " << size << " elements of size " << sizeof(T) << - std::endl; - fastos::StopWatch stopWatch; - switch (dispatch) { - case WorkFuncDispatch::DIRECT: - work(foo, writer); - break; - case WorkFuncDispatch::LAMBDA: - workLambda(foo, writer); - break; - case WorkFuncDispatch::FUNCTOR: - workFunctor(foo, writer); - break; - case WorkFuncDispatch::FUNCTOR2: - workFunctor2(foo, writer); - break; - default: - LOG_ABORT("should not be reached"); - } - double delta = stopWatch.stop().elapsed(); - double writeSpeed = writer.getBytesWritten() / delta; - EXPECT_GREATER(writeSpeed, 1000); - std::cout << "written is " << writer.getBytesWritten() << std::endl; - std::cout << "time used is " << (delta * 1000.0) << " ms" << std::endl; - std::cout << "write speed is " << writeSpeed << std::endl; -} - - -void -callWorks(WorkFuncDispatch dispatch) -{ - callWork<char>(million * 1000, dispatch); - callWork<short>(million * 500, dispatch); - callWork<int>(million * 250, dispatch); - callWork<long>(million * 125, dispatch); -} - -TEST("simple bufferwriter speed test") -{ - callWorks(WorkFuncDispatch::DIRECT); -} - -TEST("lambda func bufferwriter speed test") -{ - callWorks(WorkFuncDispatch::LAMBDA); -} - -TEST("functor bufferwriter speed test") -{ - callWorks(WorkFuncDispatch::FUNCTOR); -} - -TEST("functor2 bufferwriter speed test") -{ - callWorks(WorkFuncDispatch::FUNCTOR2); -} - - -TEST_MAIN() -{ - TEST_RUN_ALL(); -} diff --git a/searchlib/src/tests/util/bufferwriter/bufferwriter_test.cpp b/searchlib/src/tests/util/bufferwriter/bufferwriter_test.cpp index bafb4105996..33afa67e660 100644 --- a/searchlib/src/tests/util/bufferwriter/bufferwriter_test.cpp +++ b/searchlib/src/tests/util/bufferwriter/bufferwriter_test.cpp @@ -6,8 +6,7 @@ #include <vespa/searchlib/util/drainingbufferwriter.h> #include <vespa/searchlib/util/rand48.h> -namespace search -{ +namespace search { namespace { @@ -39,7 +38,7 @@ StoreBufferWriter::StoreBufferWriter() setup(&_buf[0], _buf.size()); } -StoreBufferWriter::~StoreBufferWriter() {} +StoreBufferWriter::~StoreBufferWriter() = default; void diff --git a/searchlib/src/tests/util/bufferwriter/work.cpp b/searchlib/src/tests/util/bufferwriter/work.cpp deleted file mode 100644 index bd5bf4a9d81..00000000000 --- a/searchlib/src/tests/util/bufferwriter/work.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "work.h" -#include <vespa/vespalib/util/bufferwriter.h> - -namespace search -{ - -template <class T> -class WriteFunctor -{ - BufferWriter &_writer; -public: - WriteFunctor(BufferWriter &writer) - : _writer(writer) - { - } - - void operator()(const T &val) { _writer.write(&val, sizeof(val)); } -}; - -template <class T> -class WriteFunctor2 -{ - BufferWriter &_writer; -public: - WriteFunctor2(BufferWriter &writer) - : _writer(writer) - { - } - - void operator()(const T &val) __attribute((noinline)) - { _writer.write(&val, sizeof(val)); } -}; - -template <class T, class Func> -void workLoop(const std::vector<T> &v, Func &&func) -{ - for (const auto &val : v) { - func(val); - } -} - -template <class T> -void work(const std::vector<T> &v, BufferWriter &writer) -{ - for (const auto &val : v) { - writer.write(&val, sizeof(val)); - } - writer.flush(); -} - -template <class T> -void workLambda(const std::vector<T> &v, BufferWriter &writer) -{ - workLoop<T>(v, - [&writer](const T &val) { writer.write(&val, sizeof(val)); }); - writer.flush(); -} - -template <class T> -void workFunctor(const std::vector<T> &v, BufferWriter &writer) -{ - workLoop<T>(v, WriteFunctor<T>(writer)); - writer.flush(); -} - -template <class T> -void workFunctor2(const std::vector<T> &v, BufferWriter &writer) -{ - workLoop<T>(v, WriteFunctor2<T>(writer)); - writer.flush(); -} - -template void work(const std::vector<char> &v, BufferWriter &writer); -template void work(const std::vector<short> &v, BufferWriter &writer); -template void work(const std::vector<int> &v, BufferWriter &writer); -template void work(const std::vector<long> &v, BufferWriter &writer); -template void workLambda(const std::vector<char> &v, BufferWriter &writer); -template void workLambda(const std::vector<short> &v, BufferWriter &writer); -template void workLambda(const std::vector<int> &v, BufferWriter &writer); -template void workLambda(const std::vector<long> &v, BufferWriter &writer); -template void workFunctor(const std::vector<char> &v, BufferWriter &writer); -template void workFunctor(const std::vector<short> &v, BufferWriter &writer); -template void workFunctor(const std::vector<int> &v, BufferWriter &writer); -template void workFunctor(const std::vector<long> &v, BufferWriter &writer); -template void workFunctor2(const std::vector<char> &v, BufferWriter &writer); -template void workFunctor2(const std::vector<short> &v, BufferWriter &writer); -template void workFunctor2(const std::vector<int> &v, BufferWriter &writer); -template void workFunctor2(const std::vector<long> &v, BufferWriter &writer); - -} // namespace search diff --git a/searchlib/src/tests/util/bufferwriter/work.h b/searchlib/src/tests/util/bufferwriter/work.h deleted file mode 100644 index 17f381d99eb..00000000000 --- a/searchlib/src/tests/util/bufferwriter/work.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include <vector> - -namespace search { - -class BufferWriter; - -template <class T> -using WorkFunc = void (*)(const std::vector<T> &v, BufferWriter &writer); -template <class T> -void work(const std::vector<T> &v, BufferWriter &writer); -template <class T> -void workLambda(const std::vector<T> &v, BufferWriter &writer); -template <class T> -void workFunctor(const std::vector<T> &v, BufferWriter &writer); -template <class T> -void workFunctor2(const std::vector<T> &v, BufferWriter &writer); - -} // namespace search diff --git a/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp b/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp index 57c4b3ca9a1..9d43ecfbeb4 100644 --- a/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp +++ b/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp @@ -42,9 +42,9 @@ DebugAttributeWaitExecutor::execute(uint32_t docId) _buf.fill(*_attribute, docId); waitTime = _buf[0]; } - steady_clock::time_point start = steady_clock::now(); + fastos::StopWatch timer; fastos::StopWatch::waitAtLeast(microseconds(static_cast<long>(waitTime * 1000000)), _params.busyWait); - outputs().set_number(0, (1.0e-6 * (steady_clock::now() - start)).count()); + outputs().set_number(0, timer.elapsed().sec()); } //----------------------------------------------------------------------------- diff --git a/searchlib/src/vespa/searchlib/features/debug_wait.cpp b/searchlib/src/vespa/searchlib/features/debug_wait.cpp index c30a026137c..f0a50ce8742 100644 --- a/searchlib/src/vespa/searchlib/features/debug_wait.cpp +++ b/searchlib/src/vespa/searchlib/features/debug_wait.cpp @@ -29,9 +29,9 @@ using namespace std::chrono; void DebugWaitExecutor::execute(uint32_t) { - steady_clock::time_point start = steady_clock::now(); + fastos::StopWatch timer; fastos::StopWatch::waitAtLeast(microseconds(static_cast<long>(_params.waitTime * 1000000)), _params.busyWait); - outputs().set_number(0, (1.0e-6 * (steady_clock::now() - start)).count()); + outputs().set_number(0, timer.elapsed().sec()); } //----------------------------------------------------------------------------- diff --git a/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp b/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp index 91ed78fafa3..dd0c67df45c 100644 --- a/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp +++ b/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp @@ -69,7 +69,7 @@ RandomNormalBlueprint::createExecutor(const fef::IQueryEnvironment &, vespalib:: { uint64_t seed = _seed; if (seed == 0) { - seed = static_cast<uint64_t>(duration_cast<microseconds>(steady_clock::now().time_since_epoch()).count()) ^ + seed = static_cast<uint64_t>(duration_cast<microseconds>(system_clock::now().time_since_epoch()).count()) ^ reinterpret_cast<uint64_t>(&seed); // results in different seeds in different threads } return stash.create<RandomNormalExecutor>(seed, _mean, _stddev); diff --git a/searchlib/src/vespa/searchlib/features/randomfeature.cpp b/searchlib/src/vespa/searchlib/features/randomfeature.cpp index db5ccc67a60..18b0cf616d4 100644 --- a/searchlib/src/vespa/searchlib/features/randomfeature.cpp +++ b/searchlib/src/vespa/searchlib/features/randomfeature.cpp @@ -66,7 +66,7 @@ RandomBlueprint::createExecutor(const fef::IQueryEnvironment &env, vespalib::Sta { uint64_t seed = _seed; if (seed == 0) { - seed = static_cast<uint64_t>(duration_cast<microseconds>(steady_clock::now().time_since_epoch()).count()) ^ + seed = static_cast<uint64_t>(duration_cast<microseconds>(system_clock::now().time_since_epoch()).count()) ^ reinterpret_cast<uint64_t>(&seed); // results in different seeds in different threads } uint64_t matchSeed = util::strToNum<uint64_t> |