blob: 275edafc718f5c579b1eab214cf0beb200492a97 (
plain)
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
|
#include <sys/time.h>
#include "pbd/compose.h"
#include "canvas/types.h"
#include "canvas/canvas.h"
#include "benchmark.h"
using namespace std;
using namespace ArdourCanvas;
double
double_random ()
{
return ((double) rand() / RAND_MAX);
}
ArdourCanvas::Rect
rect_random (double rough_size)
{
double const x = double_random () * rough_size / 2;
double const y = double_random () * rough_size / 2;
double const w = double_random () * rough_size / 2;
double const h = double_random () * rough_size / 2;
return Rect (x, y, x + w, y + h);
}
Benchmark::Benchmark (string const & session)
: _iterations (1)
{
string path = string_compose ("../../libs/canvas/benchmark/sessions/%1.xml", session);
_canvas = new ImageCanvas (new XMLTree (path), Duple (4096, 4096));
}
void
Benchmark::set_iterations (int n)
{
_iterations = n;
}
/** @return wallclock time in seconds */
double
Benchmark::run ()
{
timeval start;
gettimeofday (&start, 0);
for (int i = 0; i < _iterations; ++i) {
do_run (*_canvas);
}
timeval stop;
gettimeofday (&stop, 0);
finish (*_canvas);
int sec = stop.tv_sec - start.tv_sec;
int usec = stop.tv_usec - start.tv_usec;
if (usec < 0) {
--sec;
usec += 1e6;
}
return sec + ((double) usec / 1e6);
}
|