Sha256: 39352acc50eb4af39368e70c159818959d5265485966848c37dc6c5041379d81

Contents?: true

Size: 1.29 KB

Versions: 18

Compression:

Stored size: 1.29 KB

Contents

//
//  Benchmark.cpp
//  DictionarySort
//
//  Created by Samuel Williams on 2/11/11.
//  Copyright, 2014, by Samuel G. D. Williams. <http://www.codeotaku.com>
//

#include "Benchmark.h"

#include <sys/time.h>

// A timer class for quickly checking the wall-clock performance of code.
namespace Benchmark
{
	static TimeT system_time () {
		static struct timeval t;
		gettimeofday (&t, (struct timezone*)0);
		return ((TimeT)t.tv_sec) + ((TimeT)t.tv_usec / 1000000.0);
	}

	WallTime::WallTime () {
		this->reset();
	}

	void WallTime::reset () {
		this->_last = system_time();
		this->_total = 0.0;
	}

	TimeT WallTime::total () const {
		TimeT current = system_time();
		this->_total += current - this->_last;
		this->_last = current;
		return this->_total;
	}

	ProcessorTime::ProcessorTime()
	{
		this->reset();
	}

	void ProcessorTime::reset ()
	{
		this->_last = std::clock();
		this->_total = 0;
	}

	TimeT ProcessorTime::total () const
	{
		std::clock_t current = std::clock();
		this->_total += std::clock() - this->_last;
		this->_last = current;
		
		return TimeT(this->_total) / TimeT(CLOCKS_PER_SEC);
	}

	Timer::Timer()
	{
	}

	void Timer::reset ()
	{
		_wall_time.reset();
		_processor_time.reset();
	}

	Timer::Sample Timer::sample() const
	{
		return {_wall_time.total(), _processor_time.total()};
	}
}

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
build-graph-2.1.1 spec/build/graph/program/Benchmark.cpp
build-graph-2.1.0 spec/build/graph/program/Benchmark.cpp
build-graph-2.0.3 spec/build/graph/program/Benchmark.cpp
build-graph-2.0.2 spec/build/graph/program/Benchmark.cpp
build-graph-2.0.1 spec/build/graph/program/Benchmark.cpp
build-graph-2.0.0 spec/build/graph/program/Benchmark.cpp
build-graph-1.5.1 spec/build/graph/program/Benchmark.cpp
build-graph-1.4.3 spec/build/graph/program/Benchmark.cpp
build-graph-1.4.2 spec/build/graph/program/Benchmark.cpp
build-graph-1.4.1 spec/build/graph/program/Benchmark.cpp
build-graph-1.4.0 spec/build/graph/program/Benchmark.cpp
build-graph-1.3.0 spec/build/graph/program/Benchmark.cpp
build-graph-1.2.1 spec/build/graph/program/Benchmark.cpp
build-graph-1.2.0 spec/build/graph/program/Benchmark.cpp
build-graph-1.1.0 spec/build/graph/program/Benchmark.cpp
build-graph-1.0.6 spec/build/graph/program/Benchmark.cpp
build-graph-1.0.5 spec/build/graph/program/Benchmark.cpp
build-graph-1.0.4 spec/build/graph/program/Benchmark.cpp