diff options
Diffstat (limited to 'src/boost/libs/metaparse/tools/benchmark')
9 files changed, 1065 insertions, 0 deletions
diff --git a/src/boost/libs/metaparse/tools/benchmark/README.md b/src/boost/libs/metaparse/tools/benchmark/README.md new file mode 100644 index 00000000..b2fbf244 --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/README.md @@ -0,0 +1,14 @@ +This directory contains benchmarks for the library. + +The characters to use in the benchmarks and their distribution is coming from +`chars.py`. This is an automatically generated file and can be regenerated using +`char_stat.py`. It represents the distribution of characters of the Boost 1.61.0 +header files. + +To regenerate the benchmarks: + +* Generate the source files by running `generate.py`. Unless specified + otherwise, it will generate the source files found in `src` to `generated`. +* Run the benchmarks by running `benchmark.py`. Unless specified otherwise, it + will benchmark the compilation of the source files in `generated` and generate + the diagrams into the library's documentation. diff --git a/src/boost/libs/metaparse/tools/benchmark/benchmark.py b/src/boost/libs/metaparse/tools/benchmark/benchmark.py new file mode 100755 index 00000000..46d3ef9f --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/benchmark.py @@ -0,0 +1,354 @@ +#!/usr/bin/python +"""Utility to benchmark the generated source files""" + +# Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import argparse +import os +import subprocess +import json +import math +import platform +import matplotlib +import random +import re +import time +import psutil +import PIL + +matplotlib.use('Agg') +import matplotlib.pyplot # pylint:disable=I0011,C0411,C0412,C0413 + + +def benchmark_command(cmd, progress): + """Benchmark one command execution""" + full_cmd = '/usr/bin/time --format="%U %M" {0}'.format(cmd) + print '{0:6.2f}% Running {1}'.format(100.0 * progress, full_cmd) + (_, err) = subprocess.Popen( + ['/bin/sh', '-c', full_cmd], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ).communicate('') + + values = err.strip().split(' ') + if len(values) == 2: + try: + return (float(values[0]), float(values[1])) + except: # pylint:disable=I0011,W0702 + pass # Handled by the code after the "if" + + print err + raise Exception('Error during benchmarking') + + +def benchmark_file( + filename, compiler, include_dirs, (progress_from, progress_to), + iter_count, extra_flags = ''): + """Benchmark one file""" + time_sum = 0 + mem_sum = 0 + for nth_run in xrange(0, iter_count): + (time_spent, mem_used) = benchmark_command( + '{0} -std=c++11 {1} -c {2} {3}'.format( + compiler, + ' '.join('-I{0}'.format(i) for i in include_dirs), + filename, + extra_flags + ), + ( + progress_to * nth_run + progress_from * (iter_count - nth_run) + ) / iter_count + ) + os.remove(os.path.splitext(os.path.basename(filename))[0] + '.o') + time_sum = time_sum + time_spent + mem_sum = mem_sum + mem_used + + return { + "time": time_sum / iter_count, + "memory": mem_sum / (iter_count * 1024) + } + + +def compiler_info(compiler): + """Determine the name + version of the compiler""" + (out, err) = subprocess.Popen( + ['/bin/sh', '-c', '{0} -v'.format(compiler)], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ).communicate('') + + gcc_clang = re.compile('(gcc|clang) version ([0-9]+(\\.[0-9]+)*)') + + for line in (out + err).split('\n'): + mtch = gcc_clang.search(line) + if mtch: + return mtch.group(1) + ' ' + mtch.group(2) + + return compiler + + +def string_char(char): + """Turn the character into one that can be part of a filename""" + return '_' if char in [' ', '~', '(', ')', '/', '\\'] else char + + +def make_filename(string): + """Turn the string into a filename""" + return ''.join(string_char(c) for c in string) + + +def files_in_dir(path, extension): + """Enumartes the files in path with the given extension""" + ends = '.{0}'.format(extension) + return (f for f in os.listdir(path) if f.endswith(ends)) + + +def format_time(seconds): + """Format a duration""" + minute = 60 + hour = minute * 60 + day = hour * 24 + week = day * 7 + + result = [] + for name, dur in [ + ('week', week), ('day', day), ('hour', hour), + ('minute', minute), ('second', 1) + ]: + if seconds > dur: + value = seconds // dur + result.append( + '{0} {1}{2}'.format(int(value), name, 's' if value > 1 else '') + ) + seconds = seconds % dur + return ' '.join(result) + + +def benchmark(src_dir, compiler, include_dirs, iter_count): + """Do the benchmarking""" + + files = list(files_in_dir(src_dir, 'cpp')) + random.shuffle(files) + has_string_templates = True + string_template_file_cnt = sum(1 for file in files if 'bmp' in file) + file_count = len(files) + string_template_file_cnt + + started_at = time.time() + result = {} + for filename in files: + progress = len(result) + result[filename] = benchmark_file( + os.path.join(src_dir, filename), + compiler, + include_dirs, + (float(progress) / file_count, float(progress + 1) / file_count), + iter_count + ) + if 'bmp' in filename and has_string_templates: + try: + temp_result = benchmark_file( + os.path.join(src_dir, filename), + compiler, + include_dirs, + (float(progress + 1) / file_count, float(progress + 2) / file_count), + iter_count, + '-Xclang -fstring-literal-templates' + ) + result[filename.replace('bmp', 'slt')] = temp_result + except: + has_string_templates = False + file_count -= string_template_file_cnt + print 'Stopping the benchmarking of string literal templates' + + elapsed = time.time() - started_at + total = float(file_count * elapsed) / len(result) + print 'Elapsed time: {0}, Remaining time: {1}'.format( + format_time(elapsed), + format_time(total - elapsed) + ) + return result + + +def plot(values, mode_names, title, (xlabel, ylabel), out_file): + """Plot a diagram""" + matplotlib.pyplot.clf() + for mode, mode_name in mode_names.iteritems(): + vals = values[mode] + matplotlib.pyplot.plot( + [x for x, _ in vals], + [y for _, y in vals], + label=mode_name + ) + matplotlib.pyplot.title(title) + matplotlib.pyplot.xlabel(xlabel) + matplotlib.pyplot.ylabel(ylabel) + if len(mode_names) > 1: + matplotlib.pyplot.legend() + matplotlib.pyplot.savefig(out_file) + + +def mkdir_p(path): + """mkdir -p path""" + try: + os.makedirs(path) + except OSError: + pass + + +def configs_in(src_dir): + """Enumerate all configs in src_dir""" + for filename in files_in_dir(src_dir, 'json'): + with open(os.path.join(src_dir, filename), 'rb') as in_f: + yield json.load(in_f) + + +def byte_to_gb(byte): + """Convert bytes to GB""" + return byte / (1024.0 * 1024 * 1024) + + +def join_images(img_files, out_file): + """Join the list of images into the out file""" + images = [PIL.Image.open(f) for f in img_files] + joined = PIL.Image.new( + 'RGB', + (sum(i.size[0] for i in images), max(i.size[1] for i in images)) + ) + left = 0 + for img in images: + joined.paste(im=img, box=(left, 0)) + left = left + img.size[0] + joined.save(out_file) + + +def plot_temp_diagrams(config, results, temp_dir): + """Plot temporary diagrams""" + display_name = { + 'time': 'Compilation time (s)', + 'memory': 'Compiler memory usage (MB)', + } + + files = config['files'] + img_files = [] + + if any('slt' in result for result in results) and 'bmp' in files.values()[0]: + config['modes']['slt'] = 'Using BOOST_METAPARSE_STRING with string literal templates' + for f in files.values(): + f['slt'] = f['bmp'].replace('bmp', 'slt') + + for measured in ['time', 'memory']: + mpts = sorted(int(k) for k in files.keys()) + img_files.append(os.path.join(temp_dir, '_{0}.png'.format(measured))) + plot( + { + m: [(x, results[files[str(x)][m]][measured]) for x in mpts] + for m in config['modes'].keys() + }, + config['modes'], + display_name[measured], + (config['x_axis_label'], display_name[measured]), + img_files[-1] + ) + return img_files + + +def plot_diagram(config, results, images_dir, out_filename): + """Plot one diagram""" + img_files = plot_temp_diagrams(config, results, images_dir) + join_images(img_files, out_filename) + for img_file in img_files: + os.remove(img_file) + + +def plot_diagrams(results, configs, compiler, out_dir): + """Plot all diagrams specified by the configs""" + compiler_fn = make_filename(compiler) + total = psutil.virtual_memory().total # pylint:disable=I0011,E1101 + memory = int(math.ceil(byte_to_gb(total))) + + images_dir = os.path.join(out_dir, 'images') + + for config in configs: + out_prefix = '{0}_{1}'.format(config['name'], compiler_fn) + + plot_diagram( + config, + results, + images_dir, + os.path.join(images_dir, '{0}.png'.format(out_prefix)) + ) + + with open( + os.path.join(out_dir, '{0}.qbk'.format(out_prefix)), + 'wb' + ) as out_f: + qbk_content = """{0} +Measured on a {2} host with {3} GB memory. Compiler used: {4}. + +[$images/metaparse/{1}.png [width 100%]] +""".format(config['desc'], out_prefix, platform.platform(), memory, compiler) + out_f.write(qbk_content) + + +def main(): + """The main function of the script""" + desc = 'Benchmark the files generated by generate.py' + parser = argparse.ArgumentParser(description=desc) + parser.add_argument( + '--src', + dest='src_dir', + default='generated', + help='The directory containing the sources to benchmark' + ) + parser.add_argument( + '--out', + dest='out_dir', + default='../../doc', + help='The output directory' + ) + parser.add_argument( + '--include', + dest='include', + default='include', + help='The directory containing the headeres for the benchmark' + ) + parser.add_argument( + '--boost_headers', + dest='boost_headers', + default='../../../..', + help='The directory containing the Boost headers (the boost directory)' + ) + parser.add_argument( + '--compiler', + dest='compiler', + default='g++', + help='The compiler to do the benchmark with' + ) + parser.add_argument( + '--repeat_count', + dest='repeat_count', + type=int, + default=5, + help='How many times a measurement should be repeated.' + ) + + args = parser.parse_args() + + compiler = compiler_info(args.compiler) + results = benchmark( + args.src_dir, + args.compiler, + [args.include, args.boost_headers], + args.repeat_count + ) + + plot_diagrams(results, configs_in(args.src_dir), compiler, args.out_dir) + + +if __name__ == '__main__': + main() diff --git a/src/boost/libs/metaparse/tools/benchmark/char_stat.py b/src/boost/libs/metaparse/tools/benchmark/char_stat.py new file mode 100755 index 00000000..be5935dd --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/char_stat.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +"""Utility to generate character statistics about a number of source files""" + +# Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import argparse +import os + + +def count_characters(root, out): + """Count the occurrances of the different characters in the files""" + if os.path.isfile(root): + with open(root, 'rb') as in_f: + for line in in_f: + for char in line: + if char not in out: + out[char] = 0 + out[char] = out[char] + 1 + elif os.path.isdir(root): + for filename in os.listdir(root): + count_characters(os.path.join(root, filename), out) + + +def generate_statistics(root): + """Generate the statistics from all files in root (recursively)""" + out = dict() + count_characters(root, out) + return out + + +def main(): + """The main function of the script""" + desc = 'Generate character statistics from a source tree' + parser = argparse.ArgumentParser(description=desc) + parser.add_argument( + '--src', + dest='src', + required=True, + help='The root of the source tree' + ) + parser.add_argument( + '--out', + dest='out', + default='chars.py', + help='The output filename' + ) + + args = parser.parse_args() + + stats = generate_statistics(args.src) + with open(args.out, 'wb') as out_f: + out_f.write('CHARS={0}\n'.format(stats)) + + +if __name__ == '__main__': + main() diff --git a/src/boost/libs/metaparse/tools/benchmark/chars.py b/src/boost/libs/metaparse/tools/benchmark/chars.py new file mode 100644 index 00000000..95357f1e --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/chars.py @@ -0,0 +1 @@ +CHARS={' ': 22284371, '\xa3': 2, '$': 4917, '\xa7': 3, '(': 898226, '\xab': 2, ',': 2398845, '\xaf': 2, '0': 624709, '\xb3': 5, '4': 402093, '\xb7': 2, '8': 274327, '\xbb': 2, '<': 906955, '\xbf': 2, '@': 16983, '\xc3': 13, 'D': 291316, '\xc7': 2, 'H': 146671, '\xcb': 2, 'L': 404004, '\xcf': 2, 'P': 717827, '\xd3': 2, 'T': 1426865, '\xd7': 2, 'X': 80953, '\xdb': 2, '\\': 80171, '\xdf': 5, '`': 12213, '\xe3': 2, 'd': 1713185, '\xe7': 2, 'h': 787023, '\xeb': 2, 'l': 2141123, '\xef': 2, 'p': 3018561, '\xf3': 2, 't': 5917113, '\xf7': 2, 'x': 383286, '\xfb': 2, '|': 18625, '\xff': 2, '\x80': 20, '\x9c': 10, '#': 242175, '\xa4': 2, "'": 24359, '\xa8': 2, '+': 62328, '\xac': 2, '/': 1496052, '\xb0': 2, '3': 522407, '\xb4': 2, '7': 281951, '\xb8': 2, ';': 938670, '\xbc': 2, '?': 6554, '\xc0': 2, 'C': 430333, '\xc4': 2, 'G': 143243, '\xc8': 2, 'K': 90732, '\xcc': 2, 'O': 875785, '\xd0': 2, 'S': 702347, '\xd4': 2, 'W': 52216, '\xd8': 2, '[': 66305, '\xdc': 2, '_': 2992229, '\xe0': 2, 'c': 2083806, '\xe4': 2, 'g': 684087, '\xe8': 2, 'k': 165087, '\xec': 2, 'o': 3158786, '\xf0': 2, 's': 2967238, '\xf4': 2, 'w': 247018, '\xf8': 3, '{': 243686, '\xfc': 2, '\n': 2276992, '\x9d': 10, '\xa1': 2, '"': 50327, '\xa5': 2, '&': 418128, '\xa9': 4, '*': 332039, '\xad': 5, '.': 391026, '\xb1': 5, '2': 823421, '\xb5': 2, '6': 322046, '\xb9': 2, ':': 2683679, '\xbd': 2, '>': 915244, '\xc1': 2, 'B': 412447, '\xc5': 2, 'F': 174215, '\xc9': 2, 'J': 11028, '\xcd': 2, 'N': 431761, '\xd1': 2, 'R': 370532, '\xd5': 2, 'V': 120889, '\xd9': 2, 'Z': 14849, '\xdd': 2, '^': 1667, '\xe1': 2, 'b': 645436, '\xe5': 2, 'f': 1305489, '\xe9': 30, 'j': 31303, '\xed': 3, 'n': 3384988, '\xf1': 2, 'r': 2870950, '\xf5': 2, 'v': 519257, '\xf9': 2, 'z': 96213, '\xfd': 2, '~': 13463, '\t': 2920, '\r': 2276968, '!': 72758, '\xa2': 2, '%': 7081, '\xa6': 2, ')': 899122, '\xaa': 2, '-': 325139, '\xae': 2, '1': 1292007, '\xb2': 2, '5': 326024, '\xb6': 2, '9': 258472, '\xba': 4, '=': 626629, '\xbe': 2, 'A': 1040447, '\xc2': 2, 'E': 657368, '\xc6': 2, 'I': 569518, '\xca': 2, 'M': 211683, '\xce': 2, 'Q': 21541, '\xd2': 2, 'U': 218558, '\xd6': 2, 'Y': 64741, '\xda': 2, ']': 65379, '\xde': 2, 'a': 4007230, '\xe2': 22, 'e': 7280723, '\xe6': 2, 'i': 2971166, '\xea': 2, 'm': 1989243, '\xee': 2, 'q': 63623, '\xf2': 2, 'u': 1297465, '\xf6': 30, 'y': 1819692, '\xfa': 2, '}': 242894, '\xfe': 2} diff --git a/src/boost/libs/metaparse/tools/benchmark/generate.py b/src/boost/libs/metaparse/tools/benchmark/generate.py new file mode 100755 index 00000000..52526c82 --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/generate.py @@ -0,0 +1,299 @@ +#!/usr/bin/python +"""Utility to generate files to benchmark""" + +# Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import argparse +import os +import string +import random +import re +import json + +import Cheetah.Template +import chars + + +def regex_to_error_msg(regex): + """Format a human-readable error message from a regex""" + return re.sub('([^\\\\])[()]', '\\1', regex) \ + .replace('[ \t]*$', '') \ + .replace('^', '') \ + .replace('$', '') \ + .replace('[ \t]*', ' ') \ + .replace('[ \t]+', ' ') \ + .replace('[0-9]+', 'X') \ + \ + .replace('\\[', '[') \ + .replace('\\]', ']') \ + .replace('\\(', '(') \ + .replace('\\)', ')') \ + .replace('\\.', '.') + + +def mkdir_p(path): + """mkdir -p path""" + try: + os.makedirs(path) + except OSError: + pass + + +def in_comment(regex): + """Builds a regex matching "regex" in a comment""" + return '^[ \t]*//[ \t]*' + regex + '[ \t]*$' + + +def random_chars(number): + """Generate random characters""" + char_map = { + k: v for k, v in chars.CHARS.iteritems() + if not format_character(k).startswith('\\x') + } + + char_num = sum(char_map.values()) + return ( + format_character(nth_char(char_map, random.randint(0, char_num - 1))) + for _ in xrange(0, number) + ) + + +def random_string(length): + """Generate a random string or character list depending on the mode""" + return \ + 'BOOST_METAPARSE_STRING("{0}")'.format(''.join(random_chars(length))) + + +class Mode(object): + """Represents a generation mode""" + + def __init__(self, name): + self.name = name + if name == 'BOOST_METAPARSE_STRING': + self.identifier = 'bmp' + elif name == 'manual': + self.identifier = 'man' + else: + raise Exception('Invalid mode: {0}'.format(name)) + + def description(self): + """The description of the mode""" + if self.identifier == 'bmp': + return 'Using BOOST_METAPARSE_STRING' + elif self.identifier == 'man': + return 'Generating strings manually' + + def convert_from(self, base): + """Convert a BOOST_METAPARSE_STRING mode document into one with + this mode""" + if self.identifier == 'bmp': + return base + elif self.identifier == 'man': + result = [] + prefix = 'BOOST_METAPARSE_STRING("' + while True: + bmp_at = base.find(prefix) + if bmp_at == -1: + return ''.join(result) + base + else: + result.append( + base[0:bmp_at] + '::boost::metaparse::string<' + ) + new_base = '' + was_backslash = False + comma = '' + for i in xrange(bmp_at + len(prefix), len(base)): + if was_backslash: + result.append( + '{0}\'\\{1}\''.format(comma, base[i]) + ) + was_backslash = False + comma = ',' + elif base[i] == '"': + new_base = base[i+2:] + break + elif base[i] == '\\': + was_backslash = True + else: + result.append('{0}\'{1}\''.format(comma, base[i])) + comma = ',' + base = new_base + result.append('>') + + +class Template(object): + """Represents a loaded template""" + + def __init__(self, name, content): + self.name = name + self.content = content + + def instantiate(self, value_of_n): + """Instantiates the template""" + template = Cheetah.Template.Template( + self.content, + searchList={'n': value_of_n} + ) + template.random_string = random_string + return str(template) + + def range(self): + """Returns the range for N""" + match = self._match(in_comment( + 'n[ \t]+in[ \t]*\\[([0-9]+)\\.\\.([0-9]+)\\),[ \t]+' + 'step[ \t]+([0-9]+)' + )) + return range( + int(match.group(1)), + int(match.group(2)), + int(match.group(3)) + ) + + def property(self, name): + """Parses and returns a property""" + return self._get_line(in_comment(name + ':[ \t]*(.*)')) + + def modes(self): + """Returns the list of generation modes""" + return [Mode(s.strip()) for s in self.property('modes').split(',')] + + def _match(self, regex): + """Find the first line matching regex and return the match object""" + cregex = re.compile(regex) + for line in self.content.splitlines(): + match = cregex.match(line) + if match: + return match + raise Exception('No "{0}" line in {1}.cpp'.format( + regex_to_error_msg(regex), + self.name + )) + + def _get_line(self, regex): + """Get a line based on a regex""" + return self._match(regex).group(1) + + +def load_file(path): + """Returns the content of the file""" + with open(path, 'rb') as in_file: + return in_file.read() + + +def templates_in(path): + """Enumerate the templates found in path""" + ext = '.cpp' + return ( + Template(f[0:-len(ext)], load_file(os.path.join(path, f))) + for f in os.listdir(path) if f.endswith(ext) + ) + + +def nth_char(char_map, index): + """Returns the nth character of a character->occurrence map""" + for char in char_map: + if index < char_map[char]: + return char + index = index - char_map[char] + return None + + +def format_character(char): + """Returns the C-formatting of the character""" + if \ + char in string.ascii_letters \ + or char in string.digits \ + or char in [ + '_', '.', ':', ';', ' ', '!', '?', '+', '-', '/', '=', '<', + '>', '$', '(', ')', '@', '~', '`', '|', '#', '[', ']', '{', + '}', '&', '*', '^', '%']: + return char + elif char in ['"', '\'', '\\']: + return '\\{0}'.format(char) + elif char == '\n': + return '\\n' + elif char == '\r': + return '\\r' + elif char == '\t': + return '\\t' + else: + return '\\x{:02x}'.format(ord(char)) + + +def write_file(filename, content): + """Create the file with the given content""" + print 'Generating {0}'.format(filename) + with open(filename, 'wb') as out_f: + out_f.write(content) + + +def out_filename(template, n_val, mode): + """Determine the output filename""" + return '{0}_{1}_{2}.cpp'.format(template.name, n_val, mode.identifier) + + +def main(): + """The main function of the script""" + desc = 'Generate files to benchmark' + parser = argparse.ArgumentParser(description=desc) + parser.add_argument( + '--src', + dest='src_dir', + default='src', + help='The directory containing the templates' + ) + parser.add_argument( + '--out', + dest='out_dir', + default='generated', + help='The output directory' + ) + parser.add_argument( + '--seed', + dest='seed', + default='13', + help='The random seed (to ensure consistent regeneration)' + ) + + args = parser.parse_args() + + random.seed(int(args.seed)) + + mkdir_p(args.out_dir) + + for template in templates_in(args.src_dir): + modes = template.modes() + + n_range = template.range() + for n_value in n_range: + base = template.instantiate(n_value) + for mode in modes: + write_file( + os.path.join( + args.out_dir, + out_filename(template, n_value, mode) + ), + mode.convert_from(base) + ) + write_file( + os.path.join(args.out_dir, '{0}.json'.format(template.name)), + json.dumps({ + 'files': { + n: { + m.identifier: out_filename(template, n, m) + for m in modes + } for n in n_range + }, + 'name': template.name, + 'x_axis_label': template.property('x_axis_label'), + 'desc': template.property('desc'), + 'modes': {m.identifier: m.description() for m in modes} + }) + ) + + +if __name__ == '__main__': + main() diff --git a/src/boost/libs/metaparse/tools/benchmark/include/benchmark_util.hpp b/src/boost/libs/metaparse/tools/benchmark/include/benchmark_util.hpp new file mode 100644 index 00000000..eba88c92 --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/include/benchmark_util.hpp @@ -0,0 +1,281 @@ +// Copyright Szabolcs Toth (thszabi@gmail.com) 2016. +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/string.hpp> + +template <char C> +struct to_upper_char; + +template <> struct to_upper_char<-128> : boost::mpl::char_<95> {}; +template <> struct to_upper_char<-127> : boost::mpl::char_<96> {}; +template <> struct to_upper_char<-126> : boost::mpl::char_<97> {}; +template <> struct to_upper_char<-125> : boost::mpl::char_<98> {}; +template <> struct to_upper_char<-124> : boost::mpl::char_<99> {}; +template <> struct to_upper_char<-123> : boost::mpl::char_<100> {}; +template <> struct to_upper_char<-122> : boost::mpl::char_<101> {}; +template <> struct to_upper_char<-121> : boost::mpl::char_<102> {}; +template <> struct to_upper_char<-120> : boost::mpl::char_<103> {}; +template <> struct to_upper_char<-119> : boost::mpl::char_<104> {}; +template <> struct to_upper_char<-118> : boost::mpl::char_<105> {}; +template <> struct to_upper_char<-117> : boost::mpl::char_<106> {}; +template <> struct to_upper_char<-116> : boost::mpl::char_<107> {}; +template <> struct to_upper_char<-115> : boost::mpl::char_<108> {}; +template <> struct to_upper_char<-114> : boost::mpl::char_<109> {}; +template <> struct to_upper_char<-113> : boost::mpl::char_<110> {}; +template <> struct to_upper_char<-112> : boost::mpl::char_<111> {}; +template <> struct to_upper_char<-111> : boost::mpl::char_<112> {}; +template <> struct to_upper_char<-110> : boost::mpl::char_<113> {}; +template <> struct to_upper_char<-109> : boost::mpl::char_<114> {}; +template <> struct to_upper_char<-108> : boost::mpl::char_<115> {}; +template <> struct to_upper_char<-107> : boost::mpl::char_<116> {}; +template <> struct to_upper_char<-106> : boost::mpl::char_<117> {}; +template <> struct to_upper_char<-105> : boost::mpl::char_<118> {}; +template <> struct to_upper_char<-104> : boost::mpl::char_<119> {}; +template <> struct to_upper_char<-103> : boost::mpl::char_<120> {}; +template <> struct to_upper_char<-102> : boost::mpl::char_<121> {}; +template <> struct to_upper_char<-101> : boost::mpl::char_<122> {}; +template <> struct to_upper_char<-100> : boost::mpl::char_<123> {}; +template <> struct to_upper_char<-99> : boost::mpl::char_<124> {}; +template <> struct to_upper_char<-98> : boost::mpl::char_<125> {}; +template <> struct to_upper_char<-97> : boost::mpl::char_<126> {}; +template <> struct to_upper_char<-96> : boost::mpl::char_<127> {}; +template <> struct to_upper_char<-95> : boost::mpl::char_<-127> {}; +template <> struct to_upper_char<-94> : boost::mpl::char_<-126> {}; +template <> struct to_upper_char<-93> : boost::mpl::char_<-125> {}; +template <> struct to_upper_char<-92> : boost::mpl::char_<-124> {}; +template <> struct to_upper_char<-91> : boost::mpl::char_<-123> {}; +template <> struct to_upper_char<-90> : boost::mpl::char_<-122> {}; +template <> struct to_upper_char<-89> : boost::mpl::char_<-121> {}; +template <> struct to_upper_char<-88> : boost::mpl::char_<-120> {}; +template <> struct to_upper_char<-87> : boost::mpl::char_<-119> {}; +template <> struct to_upper_char<-86> : boost::mpl::char_<-118> {}; +template <> struct to_upper_char<-85> : boost::mpl::char_<-117> {}; +template <> struct to_upper_char<-84> : boost::mpl::char_<-116> {}; +template <> struct to_upper_char<-83> : boost::mpl::char_<-115> {}; +template <> struct to_upper_char<-82> : boost::mpl::char_<-114> {}; +template <> struct to_upper_char<-81> : boost::mpl::char_<-113> {}; +template <> struct to_upper_char<-80> : boost::mpl::char_<-112> {}; +template <> struct to_upper_char<-79> : boost::mpl::char_<-111> {}; +template <> struct to_upper_char<-78> : boost::mpl::char_<-110> {}; +template <> struct to_upper_char<-77> : boost::mpl::char_<-109> {}; +template <> struct to_upper_char<-76> : boost::mpl::char_<-108> {}; +template <> struct to_upper_char<-75> : boost::mpl::char_<-107> {}; +template <> struct to_upper_char<-74> : boost::mpl::char_<-106> {}; +template <> struct to_upper_char<-73> : boost::mpl::char_<-105> {}; +template <> struct to_upper_char<-72> : boost::mpl::char_<-104> {}; +template <> struct to_upper_char<-71> : boost::mpl::char_<-103> {}; +template <> struct to_upper_char<-70> : boost::mpl::char_<-102> {}; +template <> struct to_upper_char<-69> : boost::mpl::char_<-101> {}; +template <> struct to_upper_char<-68> : boost::mpl::char_<-100> {}; +template <> struct to_upper_char<-67> : boost::mpl::char_<-99> {}; +template <> struct to_upper_char<-66> : boost::mpl::char_<-98> {}; +template <> struct to_upper_char<-65> : boost::mpl::char_<-97> {}; +template <> struct to_upper_char<-64> : boost::mpl::char_<-96> {}; +template <> struct to_upper_char<-63> : boost::mpl::char_<-95> {}; +template <> struct to_upper_char<-62> : boost::mpl::char_<-94> {}; +template <> struct to_upper_char<-61> : boost::mpl::char_<-93> {}; +template <> struct to_upper_char<-60> : boost::mpl::char_<-92> {}; +template <> struct to_upper_char<-59> : boost::mpl::char_<-91> {}; +template <> struct to_upper_char<-58> : boost::mpl::char_<-90> {}; +template <> struct to_upper_char<-57> : boost::mpl::char_<-89> {}; +template <> struct to_upper_char<-56> : boost::mpl::char_<-88> {}; +template <> struct to_upper_char<-55> : boost::mpl::char_<-87> {}; +template <> struct to_upper_char<-54> : boost::mpl::char_<-86> {}; +template <> struct to_upper_char<-53> : boost::mpl::char_<-85> {}; +template <> struct to_upper_char<-52> : boost::mpl::char_<-84> {}; +template <> struct to_upper_char<-51> : boost::mpl::char_<-83> {}; +template <> struct to_upper_char<-50> : boost::mpl::char_<-82> {}; +template <> struct to_upper_char<-49> : boost::mpl::char_<-81> {}; +template <> struct to_upper_char<-48> : boost::mpl::char_<-80> {}; +template <> struct to_upper_char<-47> : boost::mpl::char_<-79> {}; +template <> struct to_upper_char<-46> : boost::mpl::char_<-78> {}; +template <> struct to_upper_char<-45> : boost::mpl::char_<-77> {}; +template <> struct to_upper_char<-44> : boost::mpl::char_<-76> {}; +template <> struct to_upper_char<-43> : boost::mpl::char_<-75> {}; +template <> struct to_upper_char<-42> : boost::mpl::char_<-74> {}; +template <> struct to_upper_char<-41> : boost::mpl::char_<-73> {}; +template <> struct to_upper_char<-40> : boost::mpl::char_<-72> {}; +template <> struct to_upper_char<-39> : boost::mpl::char_<-71> {}; +template <> struct to_upper_char<-38> : boost::mpl::char_<-70> {}; +template <> struct to_upper_char<-37> : boost::mpl::char_<-69> {}; +template <> struct to_upper_char<-36> : boost::mpl::char_<-68> {}; +template <> struct to_upper_char<-35> : boost::mpl::char_<-67> {}; +template <> struct to_upper_char<-34> : boost::mpl::char_<-66> {}; +template <> struct to_upper_char<-33> : boost::mpl::char_<-65> {}; +template <> struct to_upper_char<-32> : boost::mpl::char_<-64> {}; +template <> struct to_upper_char<-31> : boost::mpl::char_<-63> {}; +template <> struct to_upper_char<-30> : boost::mpl::char_<-62> {}; +template <> struct to_upper_char<-29> : boost::mpl::char_<-61> {}; +template <> struct to_upper_char<-28> : boost::mpl::char_<-60> {}; +template <> struct to_upper_char<-27> : boost::mpl::char_<-59> {}; +template <> struct to_upper_char<-26> : boost::mpl::char_<-58> {}; +template <> struct to_upper_char<-25> : boost::mpl::char_<-57> {}; +template <> struct to_upper_char<-24> : boost::mpl::char_<-56> {}; +template <> struct to_upper_char<-23> : boost::mpl::char_<-55> {}; +template <> struct to_upper_char<-22> : boost::mpl::char_<-54> {}; +template <> struct to_upper_char<-21> : boost::mpl::char_<-53> {}; +template <> struct to_upper_char<-20> : boost::mpl::char_<-52> {}; +template <> struct to_upper_char<-19> : boost::mpl::char_<-51> {}; +template <> struct to_upper_char<-18> : boost::mpl::char_<-50> {}; +template <> struct to_upper_char<-17> : boost::mpl::char_<-49> {}; +template <> struct to_upper_char<-16> : boost::mpl::char_<-48> {}; +template <> struct to_upper_char<-15> : boost::mpl::char_<-47> {}; +template <> struct to_upper_char<-14> : boost::mpl::char_<-46> {}; +template <> struct to_upper_char<-13> : boost::mpl::char_<-45> {}; +template <> struct to_upper_char<-12> : boost::mpl::char_<-44> {}; +template <> struct to_upper_char<-11> : boost::mpl::char_<-43> {}; +template <> struct to_upper_char<-10> : boost::mpl::char_<-42> {}; +template <> struct to_upper_char<-9> : boost::mpl::char_<-41> {}; +template <> struct to_upper_char<-8> : boost::mpl::char_<-40> {}; +template <> struct to_upper_char<-7> : boost::mpl::char_<-39> {}; +template <> struct to_upper_char<-6> : boost::mpl::char_<-38> {}; +template <> struct to_upper_char<-5> : boost::mpl::char_<-37> {}; +template <> struct to_upper_char<-4> : boost::mpl::char_<-36> {}; +template <> struct to_upper_char<-3> : boost::mpl::char_<-35> {}; +template <> struct to_upper_char<-2> : boost::mpl::char_<-34> {}; +template <> struct to_upper_char<-1> : boost::mpl::char_<-33> {}; +template <> struct to_upper_char<0> : boost::mpl::char_<-32> {}; +template <> struct to_upper_char<1> : boost::mpl::char_<-31> {}; +template <> struct to_upper_char<2> : boost::mpl::char_<-30> {}; +template <> struct to_upper_char<3> : boost::mpl::char_<-29> {}; +template <> struct to_upper_char<4> : boost::mpl::char_<-28> {}; +template <> struct to_upper_char<5> : boost::mpl::char_<-27> {}; +template <> struct to_upper_char<6> : boost::mpl::char_<-26> {}; +template <> struct to_upper_char<7> : boost::mpl::char_<-25> {}; +template <> struct to_upper_char<8> : boost::mpl::char_<-24> {}; +template <> struct to_upper_char<9> : boost::mpl::char_<-23> {}; +template <> struct to_upper_char<10> : boost::mpl::char_<-22> {}; +template <> struct to_upper_char<11> : boost::mpl::char_<-21> {}; +template <> struct to_upper_char<12> : boost::mpl::char_<-20> {}; +template <> struct to_upper_char<13> : boost::mpl::char_<-19> {}; +template <> struct to_upper_char<14> : boost::mpl::char_<-18> {}; +template <> struct to_upper_char<15> : boost::mpl::char_<-17> {}; +template <> struct to_upper_char<16> : boost::mpl::char_<-16> {}; +template <> struct to_upper_char<17> : boost::mpl::char_<-15> {}; +template <> struct to_upper_char<18> : boost::mpl::char_<-14> {}; +template <> struct to_upper_char<19> : boost::mpl::char_<-13> {}; +template <> struct to_upper_char<20> : boost::mpl::char_<-12> {}; +template <> struct to_upper_char<21> : boost::mpl::char_<-11> {}; +template <> struct to_upper_char<22> : boost::mpl::char_<-10> {}; +template <> struct to_upper_char<23> : boost::mpl::char_<-9> {}; +template <> struct to_upper_char<24> : boost::mpl::char_<-8> {}; +template <> struct to_upper_char<25> : boost::mpl::char_<-7> {}; +template <> struct to_upper_char<26> : boost::mpl::char_<-6> {}; +template <> struct to_upper_char<27> : boost::mpl::char_<-5> {}; +template <> struct to_upper_char<28> : boost::mpl::char_<-4> {}; +template <> struct to_upper_char<29> : boost::mpl::char_<-3> {}; +template <> struct to_upper_char<30> : boost::mpl::char_<-2> {}; +template <> struct to_upper_char<31> : boost::mpl::char_<-1> {}; +template <> struct to_upper_char<32> : boost::mpl::char_<0> {}; +template <> struct to_upper_char<33> : boost::mpl::char_<1> {}; +template <> struct to_upper_char<34> : boost::mpl::char_<2> {}; +template <> struct to_upper_char<35> : boost::mpl::char_<3> {}; +template <> struct to_upper_char<36> : boost::mpl::char_<4> {}; +template <> struct to_upper_char<37> : boost::mpl::char_<5> {}; +template <> struct to_upper_char<38> : boost::mpl::char_<6> {}; +template <> struct to_upper_char<39> : boost::mpl::char_<7> {}; +template <> struct to_upper_char<40> : boost::mpl::char_<8> {}; +template <> struct to_upper_char<41> : boost::mpl::char_<9> {}; +template <> struct to_upper_char<42> : boost::mpl::char_<10> {}; +template <> struct to_upper_char<43> : boost::mpl::char_<11> {}; +template <> struct to_upper_char<44> : boost::mpl::char_<12> {}; +template <> struct to_upper_char<45> : boost::mpl::char_<13> {}; +template <> struct to_upper_char<46> : boost::mpl::char_<14> {}; +template <> struct to_upper_char<47> : boost::mpl::char_<15> {}; +template <> struct to_upper_char<48> : boost::mpl::char_<16> {}; +template <> struct to_upper_char<49> : boost::mpl::char_<17> {}; +template <> struct to_upper_char<50> : boost::mpl::char_<18> {}; +template <> struct to_upper_char<51> : boost::mpl::char_<19> {}; +template <> struct to_upper_char<52> : boost::mpl::char_<20> {}; +template <> struct to_upper_char<53> : boost::mpl::char_<21> {}; +template <> struct to_upper_char<54> : boost::mpl::char_<22> {}; +template <> struct to_upper_char<55> : boost::mpl::char_<23> {}; +template <> struct to_upper_char<56> : boost::mpl::char_<24> {}; +template <> struct to_upper_char<57> : boost::mpl::char_<25> {}; +template <> struct to_upper_char<58> : boost::mpl::char_<26> {}; +template <> struct to_upper_char<59> : boost::mpl::char_<27> {}; +template <> struct to_upper_char<60> : boost::mpl::char_<28> {}; +template <> struct to_upper_char<61> : boost::mpl::char_<29> {}; +template <> struct to_upper_char<62> : boost::mpl::char_<30> {}; +template <> struct to_upper_char<63> : boost::mpl::char_<31> {}; +template <> struct to_upper_char<64> : boost::mpl::char_<32> {}; +template <> struct to_upper_char<65> : boost::mpl::char_<33> {}; +template <> struct to_upper_char<66> : boost::mpl::char_<34> {}; +template <> struct to_upper_char<67> : boost::mpl::char_<35> {}; +template <> struct to_upper_char<68> : boost::mpl::char_<36> {}; +template <> struct to_upper_char<69> : boost::mpl::char_<37> {}; +template <> struct to_upper_char<70> : boost::mpl::char_<38> {}; +template <> struct to_upper_char<71> : boost::mpl::char_<39> {}; +template <> struct to_upper_char<72> : boost::mpl::char_<40> {}; +template <> struct to_upper_char<73> : boost::mpl::char_<41> {}; +template <> struct to_upper_char<74> : boost::mpl::char_<42> {}; +template <> struct to_upper_char<75> : boost::mpl::char_<43> {}; +template <> struct to_upper_char<76> : boost::mpl::char_<44> {}; +template <> struct to_upper_char<77> : boost::mpl::char_<45> {}; +template <> struct to_upper_char<78> : boost::mpl::char_<46> {}; +template <> struct to_upper_char<79> : boost::mpl::char_<47> {}; +template <> struct to_upper_char<80> : boost::mpl::char_<48> {}; +template <> struct to_upper_char<81> : boost::mpl::char_<49> {}; +template <> struct to_upper_char<82> : boost::mpl::char_<50> {}; +template <> struct to_upper_char<83> : boost::mpl::char_<51> {}; +template <> struct to_upper_char<84> : boost::mpl::char_<52> {}; +template <> struct to_upper_char<85> : boost::mpl::char_<53> {}; +template <> struct to_upper_char<86> : boost::mpl::char_<54> {}; +template <> struct to_upper_char<87> : boost::mpl::char_<55> {}; +template <> struct to_upper_char<88> : boost::mpl::char_<56> {}; +template <> struct to_upper_char<89> : boost::mpl::char_<57> {}; +template <> struct to_upper_char<90> : boost::mpl::char_<58> {}; +template <> struct to_upper_char<91> : boost::mpl::char_<59> {}; +template <> struct to_upper_char<92> : boost::mpl::char_<60> {}; +template <> struct to_upper_char<93> : boost::mpl::char_<61> {}; +template <> struct to_upper_char<94> : boost::mpl::char_<62> {}; +template <> struct to_upper_char<95> : boost::mpl::char_<63> {}; +template <> struct to_upper_char<96> : boost::mpl::char_<64> {}; +template <> struct to_upper_char<97> : boost::mpl::char_<65> {}; +template <> struct to_upper_char<98> : boost::mpl::char_<66> {}; +template <> struct to_upper_char<99> : boost::mpl::char_<67> {}; +template <> struct to_upper_char<100> : boost::mpl::char_<68> {}; +template <> struct to_upper_char<101> : boost::mpl::char_<69> {}; +template <> struct to_upper_char<102> : boost::mpl::char_<70> {}; +template <> struct to_upper_char<103> : boost::mpl::char_<71> {}; +template <> struct to_upper_char<104> : boost::mpl::char_<72> {}; +template <> struct to_upper_char<105> : boost::mpl::char_<73> {}; +template <> struct to_upper_char<106> : boost::mpl::char_<74> {}; +template <> struct to_upper_char<107> : boost::mpl::char_<75> {}; +template <> struct to_upper_char<108> : boost::mpl::char_<76> {}; +template <> struct to_upper_char<109> : boost::mpl::char_<77> {}; +template <> struct to_upper_char<110> : boost::mpl::char_<78> {}; +template <> struct to_upper_char<111> : boost::mpl::char_<79> {}; +template <> struct to_upper_char<112> : boost::mpl::char_<80> {}; +template <> struct to_upper_char<113> : boost::mpl::char_<81> {}; +template <> struct to_upper_char<114> : boost::mpl::char_<82> {}; +template <> struct to_upper_char<115> : boost::mpl::char_<83> {}; +template <> struct to_upper_char<116> : boost::mpl::char_<84> {}; +template <> struct to_upper_char<117> : boost::mpl::char_<85> {}; +template <> struct to_upper_char<118> : boost::mpl::char_<86> {}; +template <> struct to_upper_char<119> : boost::mpl::char_<87> {}; +template <> struct to_upper_char<120> : boost::mpl::char_<88> {}; +template <> struct to_upper_char<121> : boost::mpl::char_<89> {}; +template <> struct to_upper_char<122> : boost::mpl::char_<90> {}; +template <> struct to_upper_char<123> : boost::mpl::char_<91> {}; +template <> struct to_upper_char<124> : boost::mpl::char_<92> {}; +template <> struct to_upper_char<125> : boost::mpl::char_<93> {}; +template <> struct to_upper_char<126> : boost::mpl::char_<94> {}; +template <> struct to_upper_char<127> : boost::mpl::char_<95> {}; + +template <class S> +struct to_upper; + +template <char... Cs> +struct to_upper<boost::metaparse::string<Cs...>> : + boost::metaparse::string<to_upper_char<Cs>::value...> +{}; + +#define CAT_IMPL(a, b) a ## b +#define CAT(a, b) CAT_IMPL(a, b) + +#define TEST_STRING(...) to_upper< __VA_ARGS__ >::type CAT(v, __LINE__); + diff --git a/src/boost/libs/metaparse/tools/benchmark/src/length128.cpp b/src/boost/libs/metaparse/tools/benchmark/src/length128.cpp new file mode 100644 index 00000000..768485f1 --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/src/length128.cpp @@ -0,0 +1,18 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// n in [0..2048), step 2 +// x_axis_label: Length of the 128 strings +// desc: 128 strings with increasing length. +// modes: BOOST_METAPARSE_STRING, manual + +\#define BOOST_METAPARSE_LIMIT_STRING_SIZE $n + +\#include <benchmark_util.hpp> + +#for j in range(0, 128) +TEST_STRING($random_string($n)) +#end for + diff --git a/src/boost/libs/metaparse/tools/benchmark/src/max_length.cpp b/src/boost/libs/metaparse/tools/benchmark/src/max_length.cpp new file mode 100644 index 00000000..5ea79beb --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/src/max_length.cpp @@ -0,0 +1,21 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// n in [1..2048), step 2 +// x_axis_label: Maximum length of strings +// desc: 100 one character long strings with increasing maximum length. +// modes: BOOST_METAPARSE_STRING + +\#define BOOST_METAPARSE_LIMIT_STRING_SIZE $n + +\#include <benchmark_util.hpp> + +#for j in range(0, 10) +TEST_STRING(BOOST_METAPARSE_STRING("\x0$j")) +#end for +#for j in range(10, 100) +TEST_STRING(BOOST_METAPARSE_STRING("\x$j")) +#end for + diff --git a/src/boost/libs/metaparse/tools/benchmark/src/number.cpp b/src/boost/libs/metaparse/tools/benchmark/src/number.cpp new file mode 100644 index 00000000..f15bdd23 --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/src/number.cpp @@ -0,0 +1,18 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// n in [0..1024), step 2 +// x_axis_label: Number of strings +// desc: Increasing number of strings with 64 length. +// modes: BOOST_METAPARSE_STRING, manual + +\#define BOOST_METAPARSE_LIMIT_STRING_SIZE 32 + +\#include <benchmark_util.hpp> + +#for j in range(0, $n) +TEST_STRING($random_string(32)) +#end for + |