Skip to content

Commit 3023ab5

Browse files
committed
[benchmark] BenchmarkDriver sample_time support
Added support for Benchmark_X’s `--sample-time` parameter .
1 parent bbfc064 commit 3023ab5

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

benchmark/scripts/Benchmark_Driver

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,30 @@ class BenchmarkDriver(object):
132132
return sorted(list(
133133
benchmarks.intersection(set(self.all_tests)).union(indexed_names)))
134134

135-
def run(self, test, num_samples=None, num_iters=None,
136-
verbose=None, measure_memory=False, quantile=None):
135+
def run(self, test=None, num_samples=None, num_iters=None,
136+
sample_time=None, verbose=None, measure_memory=False,
137+
quantile=None):
137138
"""Execute benchmark and gather results."""
138139
num_samples = num_samples or 0
139140
num_iters = num_iters or 0 # automatically determine N to run for 1s
141+
sample_time = sample_time or 0 # default is 1s
140142

141143
cmd = self._cmd_run(
142-
test, num_samples, num_iters, verbose, measure_memory, quantile)
144+
test, num_samples, num_iters, sample_time,
145+
verbose, measure_memory, quantile)
143146
output = self._invoke(cmd)
144147
result = self.parser.results_from_string(output).items()[0][1]
145148
return result
146149

147-
def _cmd_run(self, test, num_samples, num_iters, verbose, measure_memory,
148-
quantile):
150+
def _cmd_run(self, test, num_samples, num_iters, sample_time,
151+
verbose, measure_memory, quantile):
149152
cmd = [self.test_harness, test]
150153
if num_samples > 0:
151154
cmd.append('--num-samples={0}'.format(num_samples))
152155
if num_iters > 0:
153156
cmd.append('--num-iters={0}'.format(num_iters))
157+
if sample_time > 0:
158+
cmd.append('--sample-time={0}'.format(sample_time))
154159
if verbose:
155160
cmd.append('--verbose')
156161
if measure_memory:

benchmark/scripts/test_Benchmark_Driver.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ def test_run_benchmark_with_specified_number_of_iterations(self):
281281
self.subprocess_mock.assert_called_with(
282282
('/benchmarks/Benchmark_O', 'b', '--num-iters=1'))
283283

284+
def test_run_benchmark_for_specified_time(self):
285+
self.driver.run('b', sample_time=0.5)
286+
self.subprocess_mock.assert_called_with(
287+
('/benchmarks/Benchmark_O', 'b', '--sample-time=0.5'))
288+
284289
def test_run_benchmark_in_verbose_mode(self):
285290
self.driver.run('b', verbose=True)
286291
self.subprocess_mock.assert_called_with(

0 commit comments

Comments
 (0)