Skip to content

Commit 17c4f3e

Browse files
authored
Attempt to fix test/benchmark/benchmark_sse.py. NFC (#25355)
The script at least will run now. I'm not sure if the resulting web page is correct yet. There is a bug in the resulting html that I didn't know how to fix, but at least the python script now runs and produces html output.
1 parent 8a63417 commit 17c4f3e

File tree

6 files changed

+33
-42
lines changed

6 files changed

+33
-42
lines changed

test/sse/benchmark_sse.h renamed to test/benchmark/benchmark_sse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ float hmax(__m128 m) {
3333
return fmax(fmax(f[0], f[1]), fmax(f[2], f[3]));
3434
}
3535

36-
#include "../tick.h"
36+
#include "tick.h"
3737

3838
const int N = 8*1024*1024;
3939

test/benchmark/benchmark_sse.py

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,65 @@
77
import json
88
import os
99
import re
10-
import shutil
1110
import sys
12-
import tempfile
13-
from subprocess import Popen
11+
import subprocess
1412

15-
__rootpath__ = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
13+
__scriptdir__ = os.path.dirname(os.path.abspath(__file__))
14+
__testdir__ = os.path.dirname(os.path.dirname(__file__))
15+
__rootpath__ = os.path.dirname(__testdir__)
16+
print(__rootpath__)
1617
sys.path.insert(0, __rootpath__)
18+
sys.path.insert(0, __testdir__)
1719

18-
from tools.shared import WINDOWS, CLANG_CXX, EMCC, PIPE
20+
from tools.shared import WINDOWS, CLANG_CXX, EMCC
1921
from tools.shared import run_process
2022
from tools.config import V8_ENGINE
2123
from common import EMRUN, test_file
2224
import clang_native
2325

24-
temp_dir = tempfile.mkdtemp()
25-
2626
# System info
27-
system_info = Popen([EMRUN, '--system_info'], stdout=PIPE, stderr=PIPE).communicate()
27+
system_info = subprocess.check_output([EMRUN, '--system_info'], stderr=subprocess.STDOUT, text=True)
2828

2929
# Native info
30-
native_info = Popen(['clang', '-v'], stdout=PIPE, stderr=PIPE).communicate()
30+
native_info = subprocess.check_output(['clang', '-v'], stderr=subprocess.STDOUT, text=True)
3131

3232
# Emscripten info
33-
emscripten_info = Popen([EMCC, '-v'], stdout=PIPE, stderr=PIPE).communicate()
33+
emscripten_info = subprocess.check_output([EMCC, '-v'], stderr=subprocess.STDOUT, text=True)
3434

3535

3636
def run_benchmark(benchmark_file, results_file, build_args):
37+
out_dir = os.path.join(__rootpath__, 'out')
38+
results_file = os.path.join(out_dir, results_file)
3739
# Run native build
38-
out_file = os.path.join(temp_dir, 'benchmark_sse_native')
40+
out_file = os.path.join(out_dir, 'benchmark_sse_native')
3941
if WINDOWS:
4042
out_file += '.exe'
4143
cmd = [CLANG_CXX] + clang_native.get_clang_native_args() + [benchmark_file, '-O3', '-o', out_file]
4244
print('Building native version of the benchmark:')
4345
print(' '.join(cmd))
4446
run_process(cmd, env=clang_native.get_clang_native_env())
4547

46-
native_results = Popen([out_file], stdout=PIPE, stderr=PIPE).communicate()
47-
print(native_results[0])
48+
native_results = subprocess.check_output(out_file)
49+
print('native_results', native_results)
4850

4951
# Run emscripten build
50-
out_file = os.path.join(temp_dir, 'benchmark_sse_html.js')
51-
cmd = [EMCC, benchmark_file, '-O3', '-sTOTAL_MEMORY=536870912', '-o', out_file] + build_args
52+
out_file = os.path.join(out_dir, 'benchmark_sse_html.js')
53+
cmd = [EMCC, benchmark_file, '-sENVIRONMENT=web,shell,node', '-msimd128', '-O3', '-sTOTAL_MEMORY=536870912', '-o', out_file] + build_args
5254
print('Building Emscripten version of the benchmark:')
5355
print(' '.join(cmd))
5456
run_process(cmd)
5557

56-
cmd = V8_ENGINE + ['--experimental-wasm-simd', os.path.basename(out_file)]
58+
cmd = V8_ENGINE + [os.path.basename(out_file)]
5759
print(' '.join(cmd))
58-
old_dir = os.getcwd()
59-
os.chdir(os.path.dirname(out_file))
60-
wasm_results = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()
61-
os.chdir(old_dir)
62-
63-
if not wasm_results:
64-
raise Exception('Unable to run benchmark in V8!')
60+
wasm_results = subprocess.check_output(cmd, cwd=out_dir, text=True)
6561

66-
if not wasm_results[0].strip():
67-
print(wasm_results[1])
68-
sys.exit(1)
69-
70-
print(wasm_results[0])
62+
print('wasm_results', wasm_results)
7163

7264
def strip_comments(text):
73-
return re.sub('//.*?\n|/\*.*?\*/', '', text, re.S) # noqa
65+
return re.sub(r'//.*?\n|/\*.*?\*/', '', text, flags=re.S) # noqa
7466

75-
benchmark_results = strip_comments(wasm_results[0])
67+
benchmark_results = strip_comments(wasm_results)
68+
print('stripped', benchmark_results)
7669

7770
# Strip out unwanted print output.
7871
benchmark_results = benchmark_results[benchmark_results.find('{'):].strip()
@@ -81,9 +74,7 @@ def strip_comments(text):
8174

8275
print(benchmark_results)
8376

84-
shutil.rmtree(temp_dir)
85-
86-
native_results = json.loads(native_results[0])
77+
native_results = json.loads(native_results)
8778
benchmark_results = benchmark_results[benchmark_results.index('{'):benchmark_results.rindex('}') + 1]
8879
wasm_results = json.loads(benchmark_results)
8980

@@ -94,11 +85,11 @@ def strip_comments(text):
9485
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
9586
<script src="https://code.highcharts.com/highcharts.js"></script>
9687
<script src="https://code.highcharts.com/modules/exporting.js"></script><b>System Info:</b><br/>
97-
''' + system_info[0].replace('\n', '<br/>') + '''
88+
''' + system_info.replace('\n', '<br/>') + '''
9889
<b>Native Clang Compiler:</b><br/>
99-
''' + native_info[1].replace('\n', '<br/>') + '''
90+
''' + native_info.replace('\n', '<br/>') + '''
10091
<b>Emscripten Compiler:</b><br/>
101-
''' + emscripten_info[0].replace('\n', '<br/>')
92+
''' + emscripten_info.replace('\n', '<br/>')
10293

10394
charts_native = {}
10495
charts_html = {}
@@ -294,12 +285,12 @@ def format_comparison(a, b):
294285
if __name__ == '__main__':
295286
suite = sys.argv[1].lower() if len(sys.argv) == 2 else None
296287
if suite in ['sse', 'sse1']:
297-
run_benchmark(test_file('sse/benchmark_sse1.cpp'), 'results_sse1.html', ['-msse'])
288+
run_benchmark(test_file('benchmark/benchmark_sse1.cpp'), 'results_sse1.html', ['-msse'])
298289
elif suite == 'sse2':
299-
run_benchmark(test_file('sse/benchmark_sse2.cpp'), 'results_sse2.html', ['-msse2'])
290+
run_benchmark(test_file('benchmark/benchmark_sse2.cpp'), 'results_sse2.html', ['-msse2'])
300291
elif suite == 'sse3':
301-
run_benchmark(test_file('sse/benchmark_sse3.cpp'), 'results_sse3.html', ['-msse3'])
292+
run_benchmark(test_file('benchmark/benchmark_sse3.cpp'), 'results_sse3.html', ['-msse3'])
302293
elif suite == 'ssse3':
303-
run_benchmark(test_file('sse/benchmark_ssse3.cpp'), 'results_ssse3.html', ['-mssse3'])
294+
run_benchmark(test_file('benchmark/benchmark_ssse3.cpp'), 'results_ssse3.html', ['-mssse3'])
304295
else:
305-
raise Exception('Usage: python test/benchmark_sse.py sse1|sse2|sse3')
296+
raise Exception('Usage: python test/benchmark/benchmark_sse.py sse1|sse2|sse3')
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)