Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: client/deps/glbench/src/bench.cc

Issue 2123013: Split tests into individual files. Got rid of globals by converting them to classes. (Closed) Base URL: ssh://git@chromiumos-git//autotest.git
Patch Set: addressed comments Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/deps/glbench/src/attributefetchtest.cc ('k') | client/deps/glbench/src/cleartest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "main.h" 5 #include "main.h"
6 #include "testbase.h"
6 7
7 uint64_t TimeBench(BenchFunc func, int iter) { 8 uint64_t TimeTest(glbench::TestBase* test, int iter) {
8 SwapBuffers(); 9 SwapBuffers();
9 glFinish(); 10 glFinish();
10 uint64_t time1 = GetUTime(); 11 uint64_t time1 = GetUTime();
11 func(iter); 12 test->TestFunc(iter);
12 glFinish(); 13 glFinish();
13 uint64_t time2 = GetUTime(); 14 uint64_t time2 = GetUTime();
14 return time2 - time1; 15 return time2 - time1;
15 } 16 }
16 17
17 // Benchmark some draw commands, by running it many times. 18 // Benchmark some draw commands, by running it many times.
18 // We want to measure the marginal cost, so we try more and more iterations 19 // We want to measure the marginal cost, so we try more and more iterations
19 // until we get a somewhat linear response (to eliminate constant cost), and we 20 // until we get a somewhat linear response (to eliminate constant cost), and we
20 // do a linear regression on a few samples. 21 // do a linear regression on a few samples.
21 bool Bench(BenchFunc func, float *slope, int64_t *bias) { 22 bool Bench(glbench::TestBase* test, float *slope, int64_t *bias) {
22 // Do one iteration in case the driver needs to set up states. 23 // Do one iteration in case the driver needs to set up states.
23 if (TimeBench(func, 1) > MAX_ITERATION_DURATION_MS) 24 if (TimeTest(test, 1) > MAX_ITERATION_DURATION_MS)
24 return false; 25 return false;
25 int64_t count = 0; 26 int64_t count = 0;
26 int64_t sum_x = 0; 27 int64_t sum_x = 0;
27 int64_t sum_y = 0; 28 int64_t sum_y = 0;
28 int64_t sum_xy = 0; 29 int64_t sum_xy = 0;
29 int64_t sum_x2 = 0; 30 int64_t sum_x2 = 0;
30 uint64_t last_time = 0; 31 uint64_t last_time = 0;
31 bool do_count = false; 32 bool do_count = false;
32 uint64_t iter; 33 uint64_t iter;
33 for (iter = 8; iter < 1<<30; iter *= 2) { 34 for (iter = 8; iter < 1<<30; iter *= 2) {
34 uint64_t time = TimeBench(func, iter); 35 uint64_t time = TimeTest(test, iter);
35 if (last_time > 0 && (time > last_time * 1.8)) 36 if (last_time > 0 && (time > last_time * 1.8))
36 do_count = true; 37 do_count = true;
37 last_time = time; 38 last_time = time;
38 if (do_count) { 39 if (do_count) {
39 ++count; 40 ++count;
40 sum_x += iter; 41 sum_x += iter;
41 sum_y += time; 42 sum_y += time;
42 sum_xy += iter * time; 43 sum_xy += iter * time;
43 sum_x2 += iter * iter; 44 sum_x2 += iter * iter;
44 } 45 }
45 if ((time >= 500000 && count > 4)) 46 if ((time >= 500000 && count > 4))
46 break; 47 break;
47 } 48 }
48 if (count < 2) { 49 if (count < 2) {
49 *slope = 0.f; 50 *slope = 0.f;
50 *bias = 0; 51 *bias = 0;
51 } 52 }
52 *slope = static_cast<float>(sum_x * sum_y - count * sum_xy) / 53 *slope = static_cast<float>(sum_x * sum_y - count * sum_xy) /
53 (sum_x * sum_x - count * sum_x2); 54 (sum_x * sum_x - count * sum_x2);
54 *bias = (sum_x * sum_xy - sum_x2 * sum_y) / (sum_x * sum_x - count * sum_x2); 55 *bias = (sum_x * sum_xy - sum_x2 * sum_y) / (sum_x * sum_x - count * sum_x2);
55 return true; 56 return true;
56 } 57 }
OLDNEW
« no previous file with comments | « client/deps/glbench/src/attributefetchtest.cc ('k') | client/deps/glbench/src/cleartest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698