Giter Site home page Giter Site logo

cpp-stopwatch's Introduction

How to use this code
====================

	Not surprisingly, Stopwatch is a class representing a stopwatch.

		Stopwatch swatch();
	
	A Stopwatch object can be used to measure execution time of code, algorithms, etc., the Stopwatch can
	be initialized in two time-taking modes, CPU time and real time:
	
	
		watch.set_mode(REAL_TIME);

	CPU time is the time spent by the processor on a certain piece of code, while real time is the real
	amount of time taken by a certain piece of code to execute (i.e. in general if you are doing hard work
	such as image or video editing on a different process the measured time will probably increase).
	
	How does it work? Basically, one wraps the code to be measured with the following method calls:
	
		swatch.start("My astounding algorithm");
		// Hic est code
		swatch.stop("My astounding algorithm");
		
	A string representing the code ID is provided so that nested portions of code can be profiled separately:
	
		swatch.start("My astounding algorithm");
		
		swatch.start("My astounding algorithm - Super smart init");
		// Initialization
		swatch->stop("My astounding algorithm - Super smart init");
		
		swatch.start("My astounding algorithm - Main loop");
		// Loop
		swatch.stop("My astounding algorithm - Main loop");
		
		swatch.stop("My astounding algorithm");

	Note: ID strings can be whatever you like, in the previous example I have used "My astounding algorithm - *"
	only to enforce the fact that the measured code portions are part of My astounding algorithm, but there's no
	connection between the three measurements.
		
	If the code for a certain task is scattered through different files or portions of the same file one can use 
	the start-pause-stop method:
	
		swatch.start("Setup");
		// First part of setup
		swatch.pause("Setup");
		
		swatch.start("Main logic");
		// Main logic
		swatch.stop("Main logic");
		
		swatch.start("Setup");
		// Cleanup (part of the setup)
		swatch.stop("Setup");
		
	Finally, to report the results of the measurements just run:
	
		swatch.report("Code ID");

	Thou can also provide an additional std::ostream& parameter to report() to redirect the logging on a different
	output. Also, you can use the get_total/min/max/average_time() methods to get the individual numeric data, without
	all the details of the logging. You can also extend Stopwatch to implement your own logging syntax.
		
	To report all the measurements:
	
		swatch.report_all();

	Same as above, you can redirect the output by providing a std::ostream& parameter.	

License
=======

See LICENSE file.

Drop a line
===========

If you use this code for your software, please let me know with a mail
message at [email protected], or not.

cpp-stopwatch's People

Watchers

James Cloos avatar

cpp-stopwatch's Issues

Change report items names

My management thinks that "Stop" is counter intuitive name for viewing.
I had to replace it with "Count".
So,  like Stopwatch::SetStopsReportName("Measurments") could be useful.

Original issue reported on code.google.com by [email protected] on 15 Jan 2013 at 11:43

Pause calls clock() instead of take_time()

What steps will reproduce the problem?
Profile any code with the pause method on linux. 

What is the expected output? What do you see instead?
Non negative numbers. Negative numbers

What version of the product are you using? On what operating system?
Ubuntu 11.4

Please provide any additional information below.
The pause method calls clock() instead of take_time() thus causing an 
inconsistency with start().

Original issue reported on code.google.com by [email protected] on 29 Aug 2012 at 12:12

report_all with parameter

report_all() - by time consumed - current behavior

report_all(SW_ORDER_TIME_CONSUMED) - current

report_all(SW_ORDER_OF_FIRST_START) - by the order of first start
Now I have to put
    sw.report(msr100);
    sw.report(msr50);
    sw.report(msr10);
    sw.report(msr1);
    sw.report(msr0_1);
in the end of tests

Original issue reported on code.google.com by [email protected] on 15 Jan 2013 at 11:39

Make source forkable

Please move source to Mercurial or Git so I can fork it and make changes.
Or add me as developer.

Original issue reported on code.google.com by [email protected] on 16 Jan 2013 at 8:18

Markdown report

I use bat to run exe with you lib like

@echo Client sending request via Named pipes using custom objects reusing 
initialized resources
@echo -------------

Stopwatch outputs
================================================================================
==============
Tracking performance: Client process requests ~0.1kb and gets ~1kb response  of 
server process
================================================================================
==============
  *  Avg. time 4.40001e-005 sec
  *  Min. time 0 sec
  *  Max. time 0.00100017 sec
  *  Tot. time 0.0880003 sec
  *  Stops 2000

I could be could if instead of "=" just output **Tracking performance: Client 
process requests ~0.1kb and gets ~1kb response  of server process**.

So my bat but gives H2 size, you lib will give Bold, list of * is OK bullet 
list in terms of markdown.

I used many markups but this is so cool and usable.

So feature is 
sw.report_all(SW_LANG_MARKDOWN)

Either can add SW_LANG_YAML and SW_LANG_CSV.

Thanks





Original issue reported on code.google.com by [email protected] on 16 Jan 2013 at 8:16

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.