GithubHelp home page GithubHelp logo

sunxfancy / zeroerr Goto Github PK

View Code? Open in Web Editor NEW
21.0 3.0 1.0 8.75 MB

A powerful C++ unit testing/assert/log utils

Home Page: https://sunxfancy.github.io/zeroerr/en/html/

License: MIT License

CMake 2.40% C++ 93.18% C 3.39% Cuda 0.37% Shell 0.33% Makefile 0.33%
assert benchmarking cpp logging unit-testing assertion c-plus-plus-11 logger unit-test header-only

zeroerr's Issues

多线程logging性能的测试与优化

@bfjm 之前你提到的关于log多线程写入的问题,现在代码中的实现还比较粗糙,只有一个简单的lock-free的队列。并且你说的没错,很多log系统在多线程处理时,都会使用额外的线程来异步写入来避免对原有工作的干扰,这点非常有必要。

也许你可以帮忙建立一个多线程的写入的benchmark,测试一下性能和可靠性,并研究一下怎么样优化log的写入。我们的Test Case是可以添加Benchmark的,在test/log_test.cpp下,有一个这样的一段代码就是用来测试性能的:

BENCHMARK("speedtest") {
#ifdef ZEROERR_OS_UNIX
    uint64_t* data      = new uint64_t[1000000];
    FILE*     file      = fmemopen(data, 1000000 * sizeof(uint64_t), "w");
    FILE*     oldstdout = stdout;
    FILE*     oldstderr = stderr;
    stdout = stderr = file;
#endif
    zeroerr::LogStream::getDefault().setFlushManually();
    std::stringstream ss;
    Benchmark         bench("log speed test");
    bench.run("spdlog", [] { spdlog::info("hello world {:03.2f}", 1.1); })
        .run("stringstream",
             [&] {
                 ss << "hello world " << 1.1;
                 doNotOptimizeAway(ss);
             })
        .run("log", [] { LOG("hello world {value}", 1.1); })
        .report();
    zeroerr::LogStream::getDefault().setFlushAtOnce();

#ifdef ZEROERR_OS_UNIX
    stdout = oldstdout;
    stderr = oldstderr;
    fclose(file);
    delete[] data;
#endif
}

不过对于像一些高级profiling的功能,只有linux下才能用perf库收集。我一直想让这个东西支持windows,但无奈windows硬件寄存器太难读取了,我写了一些单独的测试代码去收集硬件信息,但一直没能找到将其整合起来的方法。如果你有兴趣也可以看下 https://github.com/sunxfancy/Win32Perf ,不过这个功能优先级比较低,并不是那么紧要。

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.