]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/metaparse/tools/benchmark/benchmark.py
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / metaparse / tools / benchmark / benchmark.py
index 8e2b0a1dd28dd19a25ffa96ac98feb8847736aee..46d3ef9faa6c8639a16a7c464db58b88ee99aa76 100755 (executable)
@@ -28,7 +28,7 @@ def benchmark_command(cmd, progress):
     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/bash', '-c', full_cmd],
+        ['/bin/sh', '-c', full_cmd],
         stdin=subprocess.PIPE,
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE
@@ -47,16 +47,17 @@ def benchmark_command(cmd, progress):
 
 def benchmark_file(
         filename, compiler, include_dirs, (progress_from, progress_to),
-        iter_count):
+        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}'.format(
+            '{0} -std=c++11 {1} -c {2} {3}'.format(
                 compiler,
                 ' '.join('-I{0}'.format(i) for i in include_dirs),
-                filename
+                filename,
+                extra_flags
             ),
             (
                 progress_to * nth_run + progress_from * (iter_count - nth_run)
@@ -75,7 +76,7 @@ def benchmark_file(
 def compiler_info(compiler):
     """Determine the name + version of the compiler"""
     (out, err) = subprocess.Popen(
-        ['/bin/bash', '-c', '{0} -v'.format(compiler)],
+        ['/bin/sh', '-c', '{0} -v'.format(compiler)],
         stdin=subprocess.PIPE,
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE
@@ -129,10 +130,13 @@ def format_time(seconds):
 
 
 def benchmark(src_dir, compiler, include_dirs, iter_count):
-    """Do the benchrmarking"""
+    """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 = {}
@@ -142,11 +146,27 @@ def benchmark(src_dir, compiler, include_dirs, iter_count):
             os.path.join(src_dir, filename),
             compiler,
             include_dirs,
-            (float(progress) / len(files), float(progress + 1) / len(files)),
+            (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(len(files) * elapsed) / len(result)
+        total = float(file_count * elapsed) / len(result)
         print 'Elapsed time: {0}, Remaining time: {1}'.format(
             format_time(elapsed),
             format_time(total - elapsed)
@@ -215,6 +235,12 @@ def plot_temp_diagrams(config, results, temp_dir):
 
     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)))