{"id":18701461,"url":"https://github.com/f-koehler/cpp-perf","last_synced_at":"2025-04-12T08:32:22.837Z","repository":{"id":23983361,"uuid":"27366491","full_name":"f-koehler/cpp-perf","owner":"f-koehler","description":"Small header-only C++11 to measure code execution time and performance.","archived":false,"fork":false,"pushed_at":"2023-05-09T08:04:21.000Z","size":85,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T03:51:14.034Z","etag":null,"topics":["benchmark","cpp","cpp11","execution-time","header-only","microbenchmark","performance"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/f-koehler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-01T06:46:13.000Z","updated_at":"2022-11-10T09:19:58.000Z","dependencies_parsed_at":"2024-11-07T11:45:33.171Z","dependency_job_id":"32fe9689-2fb7-4348-8e14-96240701dcad","html_url":"https://github.com/f-koehler/cpp-perf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-koehler%2Fcpp-perf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-koehler%2Fcpp-perf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-koehler%2Fcpp-perf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f-koehler%2Fcpp-perf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f-koehler","download_url":"https://codeload.github.com/f-koehler/cpp-perf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248540118,"owners_count":21121298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","cpp","cpp11","execution-time","header-only","microbenchmark","performance"],"created_at":"2024-11-07T11:41:41.767Z","updated_at":"2025-04-12T08:32:17.827Z","avatar_url":"https://github.com/f-koehler.png","language":"C++","readme":"# cpp-perf\n\n[![CI](https://github.com/f-koehler/cpp-perf/actions/workflows/ci.yml/badge.svg)](https://github.com/f-koehler/cpp-perf/actions/workflows/ci.yml)\n[![GitHub](https://img.shields.io/github/license/f-koehler/cpp-perf)](https://github.com/f-koehler/cpp-perf/blob/main/LICENSE)\n\nA small, header-only performance measurement library for C++11.\n\n\n## Most basic usage\n\n``` c++\n#include \u003ccpp-perf.hpp\u003e\n\nint main()\n{\n    perf::start();\n    std::this_thread::sleep_for(perf::milliseconds(20));\n    perf::stop();\n\n    return 0;\n}\n```\n\nOutput:\n```\n20 ms\n```\n\n## Inline measurement\n\n``` c++\n#include \u003ccpp-perf.hpp\u003e\n\nint main() {\n    PERF_START();\n    std::this_thread::sleep_for(perf::milliseconds(20));\n\n    PERF_START();\n    for(int i = 0; i \u003c 10; i++) {\n        std::this_thread::sleep_for(perf::milliseconds(20));\n    }\n    PERF_STOP();\n\n    PERF_STOP();\n\n    return 0;\n}\n```\n\nOutput:\n```\n/somepath/perf/example/inline.cpp:main:7-11: 200ms\n/somepath/perf/example/inline.cpp:main:4-13: 220ms\n```\nIf you put ```#ifdef PERF_DISABLE_INLINE``` in front of the include ```#include \u003ccpp-perf.hpp\u003e``` there will no measurement be performed. The macros are actually expanded int empty lines so that your code is the same as if you would not have put them there.\n\n\n## Automatic suite\n\n``` c++\n#include \u003ccpp-perf.hpp\u003e\nPERF_BEGIN(\"ExampleModule\")\n\nPERF_CASE(\"example1\",\n    std::this_thread::sleep_for(perf::milliseconds(20));\n)\n\nPERF_CASE(\"example1\",\n    for(int i = 0; i \u003c 20; i++) std::this_thread::sleep_for(perf::milliseconds(30));\n)\n\nPERF_END()\n```\n\nOutput:\n```\n1/2 Case #1: example1 .....................  Passed  20 ms\n2/2 Case #2: example2 .....................  Passed  601 ms\n```\n\n\n## Manual suites\n\n``` c++\n#include \u003ccpp-perf.hpp\u003e\n\n// you can use functions\nbool example2() {\n    std::this_thread::sleep_for(perf::milliseconds(100));\n    return true;\n}\n\n// you can use functors\nstruct example3 {\n    bool operator()() {\n        // exceptions will be caught\n        throw std::string(\"This fails!\");\n        return true;\n    }\n};\n\nint main()\n{\n    example3 functor;\n\n    // you can add cases via the constructor\n    perf::suite suite({\n        // you can use lambdas\n        { \"example1\", []() { std::this_thread::sleep_for(perf::milliseconds(40)); return true; } },\n        { \"example2\", example2},\n        { \"example3\", functor}\n    });\n\n    // you can add cases later\n    suite.add_case(\"example4\", []() { std::this_thread::sleep_for(perf::microseconds(800)); return true; });\n\n    // run all cases at once\n    suite.run();\n\n    // print results\n    std::cout \u003c\u003c suite \u003c\u003c std::endl;\n\n    return 0;\n}\n```\n\nOutput:\n```\n1/4 Case #1: example1 .....................  Passed  40 ms\n2/4 Case #2: example2 .....................  Passed  100 ms\n3/4 Case #3: example3 .....................  Failed  61 μs\n4/4 Case #4: example4 .....................  Passed  859 μs\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff-koehler%2Fcpp-perf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff-koehler%2Fcpp-perf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff-koehler%2Fcpp-perf/lists"}