mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[benchmark] Naming Convention
New benchmark naming convention for better readability and improved naming system that accounts for performance coverage growth going forward.
This commit is contained in:
@@ -293,7 +293,7 @@ class BenchmarkDoctor(object):
|
||||
self.log.addHandler(self.console_handler)
|
||||
self.log.debug('Checking tests: %s', ', '.join(self.driver.tests))
|
||||
self.requirements = [
|
||||
self._name_matches_capital_words_convention,
|
||||
self._name_matches_benchmark_naming_convention,
|
||||
self._name_is_at_most_40_chars_long,
|
||||
self._no_setup_overhead,
|
||||
self._reasonable_setup_time,
|
||||
@@ -305,20 +305,29 @@ class BenchmarkDoctor(object):
|
||||
"""Unregister handler on exit."""
|
||||
self.log.removeHandler(self.console_handler)
|
||||
|
||||
capital_words_re = re.compile('[A-Z][a-zA-Z0-9]+')
|
||||
benchmark_naming_convention_re = re.compile(r'[A-Z][a-zA-Z0-9\-\.!?]+')
|
||||
camel_humps_re = re.compile(r'[a-z][A-Z]')
|
||||
|
||||
@staticmethod
|
||||
def _name_matches_capital_words_convention(measurements):
|
||||
def _name_matches_benchmark_naming_convention(measurements):
|
||||
name = measurements['name']
|
||||
match = BenchmarkDoctor.capital_words_re.match(name)
|
||||
match = BenchmarkDoctor.benchmark_naming_convention_re.match(name)
|
||||
matched = match.group(0) if match else ''
|
||||
composite_words = len(BenchmarkDoctor.camel_humps_re.findall(name)) + 1
|
||||
|
||||
if name != matched:
|
||||
BenchmarkDoctor.log_naming.error(
|
||||
"'%s' name doesn't conform to UpperCamelCase convention.",
|
||||
"'%s' name doesn't conform to benchmark naming convention.",
|
||||
name)
|
||||
BenchmarkDoctor.log_naming.info(
|
||||
'See http://bit.ly/UpperCamelCase')
|
||||
'See http://bit.ly/BenchmarkNaming')
|
||||
|
||||
if composite_words > 4:
|
||||
BenchmarkDoctor.log_naming.warning(
|
||||
"'%s' name is composed of %d words.", name, composite_words)
|
||||
BenchmarkDoctor.log_naming.info(
|
||||
"Split '%s' name into dot-separated groups and variants. "
|
||||
"See http://bit.ly/BenchmarkNaming", name)
|
||||
|
||||
@staticmethod
|
||||
def _name_is_at_most_40_chars_long(measurements):
|
||||
|
||||
@@ -509,10 +509,14 @@ class TestBenchmarkDoctor(unittest.TestCase):
|
||||
'Measuring B1, 5 x i1 (2048 samples), 5 x i2 (2048 samples)'],
|
||||
self.logs['debug'])
|
||||
|
||||
def test_benchmark_name_matches_capital_words_conventions(self):
|
||||
def test_benchmark_name_matches_naming_conventions(self):
|
||||
driver = BenchmarkDriverMock(tests=[
|
||||
'BenchmarkName', 'CapitalWordsConvention', 'ABBRName',
|
||||
'wrongCase', 'Wrong_convention'])
|
||||
'TooManyCamelCaseHumps',
|
||||
'Existential.Array.method.1x.Val4',
|
||||
'Flatten.Array.Array.Str.for-in.reserved',
|
||||
'Flatten.Array.String?.as!.NSArray',
|
||||
'wrongCase', 'Wrong_convention', 'Illegal._$%[]<>{}@^()'])
|
||||
with captured_output() as (out, _):
|
||||
doctor = BenchmarkDoctor(self.args, driver)
|
||||
doctor.check()
|
||||
@@ -522,12 +526,22 @@ class TestBenchmarkDoctor(unittest.TestCase):
|
||||
self.assertNotIn('BenchmarkName', output)
|
||||
self.assertNotIn('CapitalWordsConvention', output)
|
||||
self.assertNotIn('ABBRName', output)
|
||||
self.assertNotIn('Existential.Array.method.1x.Val4', output)
|
||||
self.assertNotIn('Flatten.Array.Array.Str.for-in.reserved', output)
|
||||
self.assertNotIn('Flatten.Array.String?.as!.NSArray', output)
|
||||
err_msg = " name doesn't conform to benchmark naming convention."
|
||||
self.assert_contains(
|
||||
["'wrongCase' name doesn't conform to UpperCamelCase convention.",
|
||||
"'Wrong_convention' name doesn't conform to UpperCamelCase "
|
||||
"convention."], self.logs['error'])
|
||||
["'wrongCase'" + err_msg, "'Wrong_convention'" + err_msg,
|
||||
"'Illegal._$%[]<>{}@^()'" + err_msg], self.logs['error'])
|
||||
self.assert_contains(
|
||||
['See http://bit.ly/UpperCamelCase'], self.logs['info'])
|
||||
["'TooManyCamelCaseHumps' name is composed of 5 words."],
|
||||
self.logs['warning'])
|
||||
self.assert_contains(
|
||||
['See http://bit.ly/BenchmarkNaming'], self.logs['info'])
|
||||
self.assert_contains(
|
||||
["Split 'TooManyCamelCaseHumps' name into dot-separated groups "
|
||||
"and variants. See http://bit.ly/BenchmarkNaming"],
|
||||
self.logs['info'])
|
||||
|
||||
def test_benchmark_name_is_at_most_40_chars_long(self):
|
||||
driver = BenchmarkDriverMock(tests=[
|
||||
|
||||
Reference in New Issue
Block a user