Git Product home page Git Product logo

cpp-profiler's Introduction

Simple manual cpp profiler

Fork of uranix/cpp-profiler to use c++11 chrono and allow to reset the profiler.

Procs:

  • Single header
  • Profile only what you need
  • Profiling arbitrary scope
  • Early profiling scope ending

Cons:

  • Overhead ~300ns per call
  • You need to explicitely mark what you want to profile
  • May break in multithreaded environments
  • Combines calls to the same function from different contexts, e.g. if foo() -> baz(), bar() -> baz() then baz() will be shown only after foo()
  • Complex recursion (e.g. rec1 calls rec2 and rec2 calls rec1) may lead to incorrect total time for both rec1 and rec2.

Demo output

function                                                    line	calls	   tottime	avgtime

main:demo.cpp............................................... 57       1            1.01s      1.01s 
 foo for loop:demo.cpp...................................... 60       1          586.26ms   586.26ms
  double foo(int):demo.cpp.................................. 10       10         586.26ms    58.63ms
   nop:demo.cpp............................................. 17       1000000     18.41ms    18.41ns
 bar wait:demo.cpp.......................................... 66       1          200.43ms   200.43ms
  bar:demo.cpp.............................................. 23       1          100.23ms   100.23ms
 fibb:demo.cpp.............................................. 71       1          196.30ms   196.30ms
  fibb:demo.cpp............................................. 31       177        196.02ms     1.11ms
 rec1 + rec2:demo.cpp....................................... 76       1           27.78ms    27.78ms
  rec1:demo.cpp............................................. 41       89          27.75ms   311.76us
   rec2:demo.cpp............................................ 49       88          26.17ms   297.38us

function                                                    line	calls	   tottime	avgtime

main:demo.cpp............................................... 57       0            0.00ns     -nans 
 foo for loop:demo.cpp...................................... 60       0            0.00ns     -nans 
  double foo(int):demo.cpp.................................. 10       0            0.00ns     -nans 
   nop:demo.cpp............................................. 17       0            0.00ns     -nans 
 bar wait:demo.cpp.......................................... 66       0            0.00ns     -nans 
  bar:demo.cpp.............................................. 23       0            0.00ns     -nans 
 fibb:demo.cpp.............................................. 71       0            0.00ns     -nans 
 fibb:demo.cpp.............................................. 31       15          16.26ms     1.08ms
 rec1 + rec2:demo.cpp....................................... 76       0            0.00ns     -nans 
  rec1:demo.cpp............................................. 41       0            0.00ns     -nans 
   rec2:demo.cpp............................................ 49       0            0.00ns     -nans 
fibb:demo.cpp............................................... 87       1           16.29ms    16.29ms

cpp-profiler's People

Contributors

uranix avatar scsere avatar

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.