summaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-11-22 12:56:54 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-11-22 21:13:44 +0000
commiteef2bd2d629588fea48d23d4d8b481b83ce6d231 (patch)
treea024b4a0972063f194e94af6080a1bb15b47f011 /staging_vespalib
parent1ff5c508a6b7b0e6c66880abf0fe381a48eeb92f (diff)
Add a benchmark for the clock
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/tests/clock/.gitignore1
-rw-r--r--staging_vespalib/src/tests/clock/CMakeLists.txt6
-rw-r--r--staging_vespalib/src/tests/clock/clock_benchmark.cpp53
-rw-r--r--staging_vespalib/src/tests/clock/clock_test.cpp2
4 files changed, 61 insertions, 1 deletions
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 <vespa/vespalib/util/clock.h>
+#include <cassert>
+#include <vector>
+
+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<std::unique_ptr<Sampler>> threads;
+ threads.reserve(numThreads);
+ for (int i(0); i < numThreads; i++) {
+ threads.push_back(std::make_unique<Sampler>(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();