From eef2bd2d629588fea48d23d4d8b481b83ce6d231 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Fri, 22 Nov 2019 12:56:54 +0000 Subject: Add a benchmark for the clock --- staging_vespalib/src/tests/clock/.gitignore | 1 + staging_vespalib/src/tests/clock/CMakeLists.txt | 6 +++ .../src/tests/clock/clock_benchmark.cpp | 53 ++++++++++++++++++++++ staging_vespalib/src/tests/clock/clock_test.cpp | 2 +- 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 staging_vespalib/src/tests/clock/clock_benchmark.cpp (limited to 'staging_vespalib') diff --git a/staging_vespalib/src/tests/clock/.gitignore b/staging_vespalib/src/tests/clock/.gitignore index 1826ba1563b..b0fcd343176 100644 --- a/staging_vespalib/src/tests/clock/.gitignore +++ b/staging_vespalib/src/tests/clock/.gitignore @@ -2,3 +2,4 @@ Makefile clock_test staging_vespalib_clock_test_app +staging_vespalib_clock_benchmark_app diff --git a/staging_vespalib/src/tests/clock/CMakeLists.txt b/staging_vespalib/src/tests/clock/CMakeLists.txt index e62ef47e18a..825c0ae36cb 100644 --- a/staging_vespalib/src/tests/clock/CMakeLists.txt +++ b/staging_vespalib/src/tests/clock/CMakeLists.txt @@ -1,4 +1,10 @@ # Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(staging_vespalib_clock_benchmark_app TEST + SOURCES + clock_benchmark.cpp + DEPENDS + staging_vespalib +) vespa_add_executable(staging_vespalib_clock_test_app TEST SOURCES clock_test.cpp diff --git a/staging_vespalib/src/tests/clock/clock_benchmark.cpp b/staging_vespalib/src/tests/clock/clock_benchmark.cpp new file mode 100644 index 00000000000..49eac95de66 --- /dev/null +++ b/staging_vespalib/src/tests/clock/clock_benchmark.cpp @@ -0,0 +1,53 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include +#include +#include + +using vespalib::Clock; +using fastos::TimeStamp; + +struct Sampler : public FastOS_Runnable { + Sampler(Clock & clock, fastos::SteadyTimeStamp end) : + _samples(0), + _clock(clock), + _theEnd(end) + { } + void Run(FastOS_ThreadInterface *, void *) override { + printf("Starting at %s with doom at %s\n", _clock.getTimeNSAssumeRunning().toString().c_str(), _theEnd.toString().c_str()); + for (_samples = 0; (_clock.getTimeNSAssumeRunning() < _theEnd) && (_samples < 40000000000l); _samples++) { + + } + printf("Took %ld clock samples at %s\n", _samples, _clock.getTimeNSAssumeRunning().toString().c_str()); + } + uint64_t _samples; + const Clock & _clock; + fastos::SteadyTimeStamp _theEnd; + FastOS_ThreadInterface * _thread; +}; +void sample() { + +} + +int +main(int , char *argv[]) +{ + long frequency = atoll(argv[1]); + int numThreads = atoi(argv[2]); + Clock clock(1.0/frequency); + FastOS_ThreadPool pool(0x10000); + assert(pool.NewThread(&clock, nullptr) != nullptr); + + std::vector> threads; + threads.reserve(numThreads); + for (int i(0); i < numThreads; i++) { + threads.push_back(std::make_unique(clock, fastos::ClockSteady::now() + 10*TimeStamp::SEC)); + Sampler * sampler = threads[i].get(); + sampler->_thread = pool.NewThread(threads[i].get(), nullptr); + } + for (const auto & sampler : threads) { + sampler->_thread->Join(); + } + pool.Close(); + clock.stop(); +} diff --git a/staging_vespalib/src/tests/clock/clock_test.cpp b/staging_vespalib/src/tests/clock/clock_test.cpp index 45f17bbba92..c8c93272e85 100644 --- a/staging_vespalib/src/tests/clock/clock_test.cpp +++ b/staging_vespalib/src/tests/clock/clock_test.cpp @@ -20,7 +20,7 @@ Test::Main() Clock clock(0.050); FastOS_ThreadPool pool(0x10000); - ASSERT_TRUE(pool.NewThread(&clock, NULL) != NULL); + ASSERT_TRUE(pool.NewThread(&clock, nullptr) != nullptr); fastos::SteadyTimeStamp start = clock.getTimeNS(); FastOS_Thread::Sleep(5000); fastos::SteadyTimeStamp stop = clock.getTimeNS(); -- cgit v1.2.3