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

Side by Side Diff: tools/perf/metrics/discrepancy_unittest.py

Issue 23506030: telemetry: Add new metrics to smoothness benchmark. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 3 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 | « tools/perf/metrics/discrepancy.py ('k') | tools/perf/metrics/gpu_rendering_stats.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import unittest
5 import random
6
7 from metrics import discrepancy
8
9 def Relax(samples, iterations=10):
10 ''' Lloyd relaxation in 1D. Keeps the position of the first and last
11 sample.
12 '''
13 for _ in xrange(0, iterations):
14 voronoi_boundaries = []
15 for i in xrange(1, len(samples)):
16 voronoi_boundaries.append((samples[i] + samples[i-1]) * 0.5)
17
18 relaxed_samples = []
19 relaxed_samples.append(samples[0])
20 for i in xrange(1, len(samples)-1):
21 relaxed_samples.append(
22 (voronoi_boundaries[i-1] + voronoi_boundaries[i]) * 0.5)
23 relaxed_samples.append(samples[-1])
24 samples = relaxed_samples
25 return samples
26
27 class DiscrepancyUnitTest(unittest.TestCase):
28 def testRandom(self):
29 ''' Generates 10 sets of 10 random samples, computes the discrepancy,
30 relaxes the samples using Llloyd's algorithm in 1D, and computes the
31 discrepancy of the relaxed samples. Discrepancy of the relaxed samples
32 must be less than or equal to the discrepancy of the original samples.
33 '''
34 random.seed(1234567)
35 for _ in xrange(0, 10):
36 samples = []
37 num_samples = 10
38 clock = 0.0
39 samples.append(clock)
40 for _ in xrange(1, num_samples):
41 clock += random.random()
42 samples.append(clock)
43 samples = discrepancy.NormalizeSamples(samples)[0]
44 d = discrepancy.Discrepancy(samples)
45
46 relaxed_samples = Relax(samples)
47 d_relaxed = discrepancy.Discrepancy(relaxed_samples)
48
49 self.assertLessEqual(d_relaxed, d)
50
51 def testAnalytic(self):
52 ''' Computes discrepancy for sample sets with known discrepancy. '''
53 interval_multiplier = 100000
54
55 samples = [1.0/8.0, 3.0/8.0, 5.0/8.0, 7.0/8.0]
56 d = discrepancy.Discrepancy(samples, interval_multiplier)
57 self.assertAlmostEquals(round(d, 2), 0.25)
58
59 samples = [0.0, 1.0/3.0, 2.0/3.0, 1.0]
60 d = discrepancy.Discrepancy(samples, interval_multiplier)
61 self.assertAlmostEquals(round(d, 2), 0.5)
62
63 samples = discrepancy.NormalizeSamples(samples)[0]
64 d = discrepancy.Discrepancy(samples, interval_multiplier)
65 self.assertAlmostEquals(round(d, 2), 0.25)
66
67 time_stamps_a = [0, 1, 2, 3, 5, 6]
68 time_stamps_b = [0, 1, 2, 3, 5, 7]
69 time_stamps_c = [0, 2, 3, 4]
70 time_stamps_d = [0, 2, 3, 4, 5]
71 d_abs_a = discrepancy.FrameDiscrepancy(time_stamps_a, True,
72 interval_multiplier)
73 d_abs_b = discrepancy.FrameDiscrepancy(time_stamps_b, True,
74 interval_multiplier)
75 d_abs_c = discrepancy.FrameDiscrepancy(time_stamps_c, True,
76 interval_multiplier)
77 d_abs_d = discrepancy.FrameDiscrepancy(time_stamps_d, True,
78 interval_multiplier)
79 d_rel_a = discrepancy.FrameDiscrepancy(time_stamps_a, False,
80 interval_multiplier)
81 d_rel_b = discrepancy.FrameDiscrepancy(time_stamps_b, False,
82 interval_multiplier)
83 d_rel_c = discrepancy.FrameDiscrepancy(time_stamps_c, False,
84 interval_multiplier)
85 d_rel_d = discrepancy.FrameDiscrepancy(time_stamps_d, False,
86 interval_multiplier)
87
88 self.assertLess(d_abs_a, d_abs_b)
89 self.assertLess(d_rel_a, d_rel_b)
90 self.assertLess(d_rel_d, d_rel_c)
91 self.assertEquals(round(d_abs_d, 2), round(d_abs_c, 2))
OLDNEW
« no previous file with comments | « tools/perf/metrics/discrepancy.py ('k') | tools/perf/metrics/gpu_rendering_stats.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698