Commit e3d315e5 by amir

add commonutils

parent bb9ac7a2
//
// Created by amir on 28/03/17.
//
#ifndef MICROSERVICE_COMMONUTILS_H
#define MICROSERVICE_COMMONUTILS_H
#include <chrono>
#include <utility>
/**
* common utils
*/
class CommonUtils {
public:
/**
* measuring execution of a function
* @tparam TimeT time unit (default milliseconds)
* @param func function
* @param args function args
* @return
*/
template<typename TimeT = std::chrono::milliseconds,typename F, typename ...Args>
static typename TimeT::rep measureFunc(F&& func, Args&&... args)
{
auto start = std::chrono::steady_clock::now();
std::forward<decltype(func)>(func)(std::forward<Args>(args)...);
auto duration = std::chrono::duration_cast< TimeT>
(std::chrono::steady_clock::now() - start);
return duration.count();
}
};
#endif //MICROSERVICE_COMMONUTILS_H
......@@ -8,6 +8,7 @@
#include <iostream>
#include <common/Microservice_MsgQContext.h>
#include <thread>
#include <utils/CommonUtils.h>
static const char *const IPC_FILE1 = "/tmp/service-name1.ipc";
static const char *const IPC_FILE2 = "/tmp/service-name2.ipc";
......@@ -239,7 +240,9 @@ void test_pubsub(zmqpp::context &context) {
int main(int argc, char *argv[]) {
zmqpp::context context;
std::cout << "testing of " << ITERATIONS << " iterations took: " << measure<>::execution(testRequestResponse,context) << " msec" << std::endl;
// std::cout << "testing of " << ITERATIONS << " iterations took: " << measure<>::execution(testRequestResponse,context) << " msec" << std::endl;
std::cout << "testing of " << ITERATIONS << " iterations took: " << CommonUtils::measureFunc<>(testRequestResponse,context) << " msec" << std::endl;
//testRequestResponse(context);
//test_pubsub(context);
//test_Cereal();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment