]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3793] Performance benchmarks added.
authorTomek Mrugalski <tomasz@isc.org>
Fri, 8 May 2015 16:36:13 +0000 (18:36 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 8 May 2015 16:36:13 +0000 (18:36 +0200)
src/lib/stats/tests/stats_mgr_unittest.cc

index d1e58f7f5c8307db251a7ffb74581d61a670cc9b..4c1cb5f88440c079916fdd262d99e9ffcfcfb412 100644 (file)
@@ -286,4 +286,108 @@ TEST_F(StatsMgrTest, removeAll) {
     EXPECT_FALSE(StatsMgr::instance().getObservation("delta"));
 }
 
+// This is a performance benchmark that checks how long does it take
+// to increment a single statistic million times.
+//
+// Data points:
+// It took 00:00:00.363709 (363ms) on late 2013 Mac with Mac OS X 10.9.5.
+TEST_F(StatsMgrTest, DISABLED_performanceSingleAdd) {
+    StatsMgr::instance().removeAll();
+
+    uint32_t cycles = 1000000;
+
+    ptime before = microsec_clock::local_time();
+    for (uint32_t i = 0; i < cycles; ++i) {
+        StatsMgr::instance().addValue("metric1", 0.1*i);
+    }
+    ptime after = microsec_clock::local_time();
+
+    time_duration dur = after - before;
+
+    std::cout << "Incrementing a single statistic " << cycles << " times took: "
+              << Observation::durationToText(dur) << std::endl;
+}
+
+// This is a performance benchmark that checks how long does it take
+// to set absolute value of a single statistic million times.
+//
+// Data points:
+// It took 00:00:00.361003 (361ms) on late 2013 Mac with Mac OS X 10.9.5.
+TEST_F(StatsMgrTest, DISABLED_performanceSingleSet) {
+    StatsMgr::instance().removeAll();
+
+    uint32_t cycles = 1000000;
+
+    ptime before = microsec_clock::local_time();
+    for (uint32_t i = 0; i < cycles; ++i) {
+        StatsMgr::instance().setValue("metric1", 0.1*i);
+    }
+    ptime after = microsec_clock::local_time();
+
+    time_duration dur = after - before;
+
+    std::cout << "Setting a single statistic " << cycles << " times took: "
+              << Observation::durationToText(dur) << std::endl;
+}
+
+// This is a performance benchmark that checks how long does it take to
+// increment one statistic a million times, when there is 1000 other statistics
+// present.
+//
+// Data points:
+// 00:00:00.436943 (436ms) on late 2013 Mac with Mac OS X 10.9.5
+TEST_F(StatsMgrTest, DISABLED_performanceMultipleAdd) {
+    StatsMgr::instance().removeAll();
+
+    uint32_t cycles = 1000000;
+    uint32_t stats = 1000;
+
+    for (uint32_t i = 0; i < stats; ++i) {
+        std::stringstream tmp;
+        tmp << "statistic" << i;
+        StatsMgr::instance().setValue(tmp.str(), static_cast<uint64_t>(i));
+    }
+
+    ptime before = microsec_clock::local_time();
+    for (uint32_t i = 0; i < cycles; ++i) {
+        StatsMgr::instance().addValue("metric1", static_cast<uint64_t>(i));
+    }
+    ptime after = microsec_clock::local_time();
+
+    time_duration dur = after - before;
+
+    std::cout << "Incrementing one of " << stats << " statistics " << cycles
+              << " times took: " << Observation::durationToText(dur) << std::endl;
+}
+
+// This is a performance benchmark that checks how long does it take to
+// set one statistic to a given value a million times, when there is 1000 other
+// statistics present.
+//
+// Data points:
+// 00:00:00.424518 (424ms) on late 2013 Mac with Mac OS X 10.9.5
+TEST_F(StatsMgrTest, DISABLED_performanceMultipleSet) {
+    StatsMgr::instance().removeAll();
+
+    uint32_t cycles = 1000000;
+    uint32_t stats = 1000;
+
+    for (uint32_t i = 0; i < stats; ++i) {
+        std::stringstream tmp;
+        tmp << "statistic" << i;
+        StatsMgr::instance().setValue(tmp.str(), static_cast<uint64_t>(i));
+    }
+
+    ptime before = microsec_clock::local_time();
+    for (uint32_t i = 0; i < cycles; ++i) {
+        StatsMgr::instance().setValue("metric1", static_cast<uint64_t>(i));
+    }
+    ptime after = microsec_clock::local_time();
+
+    time_duration dur = after - before;
+
+    std::cout << "Setting one of " << stats << " statistics " << cycles
+              << " times took: " << Observation::durationToText(dur) << std::endl;
+}
+
 };