Giter Club home page Giter Club logo

mkn.kul's Introduction

mkn.kul

Cross platform C++ wrapper for threading/process management/io/logging/signal handling and stack walking.

Supported Architectures/Operating Systems:

x86_64 / Linux
x86_64 / BSD
x86_64 / Windows
ARMv7  / Linux
ARMv7  / Windows
ARM64  / Linux (TBC - should work, stack walking might not)

mkn.kul's People

Contributors

philipdeegan avatar thehandsomecoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mkn.kul's Issues

function timing

essentially

#include <string_view>
#include <cstdint>
#include <iostream>
#include <vector>
#include <thread>
#include <chrono>

#define PRINT(...) std::cout << __FILE__ << " " << __LINE__ << " " << __VA_ARGS__ << std::endl;

std::uint64_t now() {
    return std::chrono::duration_cast<std::chrono::milliseconds>(
               std::chrono::system_clock::now().time_since_epoch())
        .count();
}

struct Report;

static std::vector<Report*> reports;

struct Report {
    std::string_view s;
    std::uint32_t l = 0;

    Report(std::string_view const& sv, std::uint32_t const& _l) : s{sv}, l{_l} {
        reports.emplace_back(this);
    }

    std::vector<std::uint32_t> times;
};

struct scope_timer {
    Report& r;
    std::uint64_t const start = now();
    ~scope_timer() noexcept { r.times.emplace_back(now() - start); }
};

#define SCOPE_TIMER                                    \
    static Report ridx_##__LINE__{__FILE__, __LINE__}; \
    scope_timer _scope_timer_##__LINE__{ridx_##__LINE__};

void fn0() {
    SCOPE_TIMER;
    using namespace std::chrono_literals;
    std::this_thread::sleep_for(100ms);
}

void fn1() {
    SCOPE_TIMER;
    using namespace std::chrono_literals;
    std::this_thread::sleep_for(100ms);
    fn0();
}

int main() {
    for (std::size_t i = 0; i < 5; ++i) fn1();

    for (auto const& rp : reports) {
        auto const& r = *rp;
        PRINT(r.s << " " << r.l);
        for (auto const& t : r.times) PRINT(t);
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.