File: Benchmark.cc

package info (click to toggle)
tagcoll2 2.0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,524 kB
  • ctags: 1,624
  • sloc: sh: 11,709; cpp: 6,201; makefile: 195; ansic: 74; lex: 54; yacc: 27
file content (74 lines) | stat: -rw-r--r-- 1,448 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "Benchmark.h"
#include <wibble/exception.h>

#include <stdarg.h>
#include <time.h>
#include <iostream>

using namespace std;

Timer::~Timer()
{
	done();
}

void Timer::done()
{
	if (start != -1)
	{
		clock_t end = clock();

		cout << desc << ": " << (double)(end - start) / (double)CLOCKS_PER_SEC * 1000.0 << "ms" << endl;

		start = -1;
	}
}


static Benchmark* _root = 0;
Benchmark* Benchmark::root()
{
	if (!_root)
		_root = new Benchmark("");
	return _root;
}


// Run only the subtest at the given path
void Benchmark::run(const std::string& path)
{
	size_t split = path.find('/');
	if (split == std::string::npos)
	{
		for (std::vector<Benchmark*>::iterator i = children.begin();
				i != children.end(); i++)
			if ((*i)->name() == path)
				return (*i)->run();
	} else {
		std::string child(path, 0, split);
		std::string nextpath(path, split+1);

		for (std::vector<Benchmark*>::iterator i = children.begin();
				i != children.end(); i++)
			if ((*i)->name() == child)
				return (*i)->run(nextpath);
	}
	throw wibble::exception::Consistency("looking for benchmark " + path + " at " + fullName(), "benchmark not found");
}

// Run all subtests and this test
void Benchmark::run()
{
	// First, run children
	if (! children.empty())
	{
		Timer t = mktimer("total");
		for (std::vector<Benchmark*>::iterator i = children.begin();
				i != children.end(); i++)
			(*i)->run();
	}

	// Then, run self
	main();
}
// vim:set ts=4 sw=4: